Part Number Hot Search : 
TPR1000 1N965 RGPP15A OM5220DC RFZ24N D1835 TA2055F 60R199
Product Description
Full Text Search
 

To Download UPD17132GT-XXX Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  document no. ieu-1367a (o. d. no. ieu-835a) date published july 1995 p printed in japan m pd17120 m pd17121 m pd17132 m pd17133 m pd17p132 m pd17p133 m pd17120 subseries 4-bit single-chip microcontroller 1993
notes for cmos devices 1 precaution against esd for semiconductors note: strong electric field, when exposed to a mos device, can cause destruction of the gate oxide and ultimately degrade the device operation. steps must be taken to stop generation of static electricity as much as possible, and quickly dissipate it once, when it has occurred. environ- mental control must be adequate. when it is dry, humidifier should be used. it is recommended to avoid using insulators that easily build static electricity. semiconductor devices must be stored and transported in an anti-static container, static shielding bag or conductive material. all test and measurement tools including work bench and floor should be grounded. the operator should be grounded using wrist strap. semiconductor devices must not be touched with bare hands. similar precautions need to be taken for pw boards with semiconductor devices on it. 2 handling of unused input pins for cmos note: no connection for cmos device inputs can be cause of malfunction. if no connection is provided to the input pins, it is possible that an internal input level may be generated due to noise, etc., hence causing malfunction. cmos devices behave differently than bipolar or nmos devices. input levels of cmos devices must be fixed high or low by using a pull-up or pull-down circuitry. each unused pin should be connected to v dd or gnd with a resistor, if it is considered to have a possibility of being an output pin. all handling related to the unused pins must be judged device by device and related specifications governing the devices. 3 status before initialization of mos devices note: power-on does not necessarily define initial status of mos device. production process of mos does not define the initial operation status of the device. immediately after the power source is turned on, the devices with reset function have not yet been initialized. hence, power-on does not guarantee out-pin levels, i/o settings or contents of registers. device is not initialized until the reset signal is received. reset operation must be executed immediately after power- on for devices having reset function. simplehost is a trademark of nec corporation. ms-dos tm and windows tm are trademarks of microsoft corporation. pc/at and pc dos are trademarks of ibm corporation.
the export of this product from japan is regulated by the japanese government. to export this product may be prohibited without governmental license, the need for which must be judged by the customer. the export or re- export of this product from a country other than japan may also be prohibited without a license from that country. please call an nec sales representative. the information in this document is subject to change without notice. no part of this document may be copied or reproduced in any form or by any means without the prior written consent of nec corporation. nec corporation assumes no responsibility for any errors which may appear in this document. nec corporation does not assume any liability for infringement of patents, copyrights or other intellectual property rights of third parties by or arising from use of a device described herein or any other liability arising from use of such device. no license, either express, implied or otherwise, is granted under any patents, copyrights or other intellectual property rights of nec corporation or others. while nec corporation has been making continuous effort to enhance the reliability of its semiconductor devices, the possibility of defects cannot be eliminated entirely. to minimize risks of damage or injury to persons or property arising from a defect in an nec semiconductor device, customer must incorporate sufficient safety measures in its design, such as redundancy, fire-containment, and anti-failure features. nec devices are classified into the following three quality grades: standard, special, and specific. the specific quality grade applies only to devices developed based on a customer designated quality assurance program for a specific application. the recommended applications of a device depend on its quality grade, as indicated below. customers must check the quality grade of each device before using it in a particular application. standard: computers, office equipment, communications equipment, test and measurement equipment, audio and visual equipment, home electronic appliances, machine tools, personal electronic equipment and industrial robots special: transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster systems, anti-crime systems, safety equipment and medical equipment (not specifically designed for life support) specific: aircrafts, aerospace equipment, submersible repeaters, nuclear reactor control systems, life support systems or medical equipment for life support, etc. the quality grade of nec devices in standard unless otherwise specified in nec's data sheets or data books. if customers intend to use nec devices for applications other than those specified for standard quality grade, they should contact nec sales representative in advance. anti-radioactive design is not implemented in this product. m7 94.11
introduction targeted reader this manual is intended for the user engineers who understand functions of the m pd17120 subseries and design their application systems using the m pd17120 sub- series purpose the purpose of this manual is for the user to understand the hardware functions of the m pd17120 subseries. use the manual assumes that the reader has a general knowledge of electricity, logic circuits, microcontrollers. ? to understand the functions of the m pd17120 subseries in a general way; ? read the manual from chapter 1. ? to look up instruction functions in detail when you know the mnemonic of an instruction; ? use appendix d instruction list. ? to look up an instruction when you do not know its mnemonic but know outlines of the function; ? refer to 18.3 list of the instruction set for search for the mnemonic of the instruction, then see 18.5 instructions for the function. ? to look up electrical characteristics of the m pd17120 subseries; ? refer to data sheet. legend data representation weight : high-order and low-order digits are indicated from left to right. active low representation : (pin or signal name is overlined) address of memory map : top: low, bottom: high note : explanation of note in the text caution : caution to which you should pay attention remark : supplementary explanation to the text number representation : binary number ... or b decimal number ... or d hexadecimal number ... h
eeu-847 [eeu-1412] eeu-603 [eeu-1287] eeu-907 [eeu-1464] relevant documents the following documents are provided for the m pd17120 subseries. the numbers listed in the table are the document numbers. some related documents are preliminary versions. this document, however, is not indicated as "preliminary". part number m pd17120 m pd17121 m pd17132 m pd17133 m pd17p132 m pd17p133 document name data sheet ic-8407 ic-8399 ic-8412 ic-8411 id-8419 id-8426 [ic-2972] [ic-2976] [ic-2973] [ic-2974] [id-2971] [id-2983] user's manual this manual [ieu-1367] ie-17k clice ver.1.6 eeu-929 [eeu-1467] user's manual ie-17k-et clice-et ver.1.6 eeu-931 [eeu-1466] user's manual se board user's manual simplehost tm eeu-723 [eeu-1336] (introduction) user's manual eeu-724 [eeu-1337] (reference) as17k (ver.1.11) user's manual device file user's manual remark the numbers inside [ ] indicate english document number. the m pd17120 subseries has different pin names and signal names depending on the system clock type, as shown in the table below. system clock rc oscillation ceramic oscillation m pd17120 m pd17121 m pd17132 m pd17133 pin/signal names m pd17p132 m pd17p133 osc 1 x in osc 0 x out system clock frequency f cc f x unless otherwise specified, this manual uses x in , x out , and f x for descriptions. when using the m pd17120, 17132, and 17p132, please change the readings to osc 1 , osc 0 and f cc . system clock oscillation pin
C i C table of contents chapter 1 general ..................................................................................................................... 1 1.1 function list ................................................................................................................ 2 1.2 ordering information ............................................................................................. 3 1.3 block diagram ............................................................................................................. 4 1.4 pin configuration (top view) ................................................................................. 6 chapter 2 pin functions ......................................................................................................... 9 2.1 pin functions ............................................................................................................... 9 2.1.1 pins in normal operation mode ......................................................................................... 9 2.1.2 pins in program memory write/verify mode ... m pd17p132, 17p133 only ..................... 11 2.2 pin input/output circuit ......................................................................................... 12 2.3 handling unused pins .............................................................................................. 17 2.4 cautions on use of the reset and int pins (in normal operation mode only) ................................................................................. 18 chapter 3 program counter (pc) ....................................................................................... 19 3.1 program counter configuration ...................................................................... 19 3.2 program counter operation ................................................................................ 19 3.2.1 program counter at reset .................................................................................................. 20 3.2.2 program counter during execution of the branch instruction (br) .................................. 20 3.2.3 program counter during execution of subroutine calls (call) ....................................... 21 3.2.4 program counter during execution of return instructions (ret, retsk, reti) ............. 22 3.2.5 program counter during table reference (movt) ............................................................ 22 3.2.6 program counter during execution of skip instructions (ske, skge, sklt, skne, skt skf) .................................................................................. 22 3.2.7 program counter when an interrupt is received ............................................................. 22 3.3 cautions on program counter operation .................................................... 22 chapter 4 program memory (rom) .................................................................................... 23 4.1 program memory configuration ....................................................................... 23 4.2 program memory usage ......................................................................................... 24 4.2.1 flow of the program ........................................................................................................... 24 4.2.2 table reference .................................................................................................................. 27 chapter 5 data memory (ram) ............................................................................................. 31 5.1 data memory configuration ................................................................................ 31 5.1.1 system register (sysreg) ................................................................................................. 32 5.1.2 data buffer (dbf) ................................................................................................................ 32 5.1.3 general register (gr) ......................................................................................................... 32 5.1.4 port registers ...................................................................................................................... 33
C ii C 5.1.5 general data memory ......................................................................................................... 33 5.1.6 uninstalled data memory ................................................................................................... 33 chapter 6 stack ........................................................................................................................ 35 6.1 stack configuration ................................................................................................ 35 6.2 functions of the stack ........................................................................................... 35 6.3 address stack register .......................................................................................... 36 6.4 interrupt stack register ....................................................................................... 36 6.5 stack pointer (sp) and interrupt stack register ....................................... 36 6.6 stack operation during subroutines, table references, and interrupts ............................................................................................................ 37 6.6.1 stack operation during subroutine calls (call) and returns (ret, retsk) .................. 37 6.6.2 stack operation during table reference (movt dbf, @ar) ........................................... 38 6.6.3 executing reti instruction .................................................................................................. 39 6.7 stack nesting levels and the push and pop instructions ................... 39 chapter 7 system register (sysreg) ................................................................................. 41 7.1 system register configuration .......................................................................... 41 7.2 address register (ar) ............................................................................................... 43 7.2.1 address register configuration .......................................................................................... 43 7.2.2 address register functions ................................................................................................ 43 7.3 window register (wr) ............................................................................................... 45 7.3.1 window register configuration .......................................................................................... 45 7.3.2 window register functions ................................................................................................ 45 7.4 bank register (bank) ................................................................................................. 46 7.5 index register (ix) and data memory row address pointer (memory pointer: mp) .................................................................................................... 47 7.5.1 index register (ix) ............................................................................................................... 47 7.5.2 data memory row address pointer (memory pointer: mp) ........................................... 47 7.5.3 mpe=0 and ixe=0 (no data memory modification) ......................................................... 50 7.5.4 mpe=1 and ixe=0 (diagonal indirect data transfer) ........................................................ 52 7.5.5 mpe=0 and ixe=1 (index modification) ............................................................................. 54 7.6 general register pointer (rp) .............................................................................. 59 7.6.1 general register pointer configuration .............................................................................. 59 7.6.2 functions of the general register pointer ......................................................................... 60 7.7 program status word (psword) ........................................................................ 61 7.7.1 program status word configuration .................................................................................. 61 7.7.2 functions of the program status word ............................................................................. 62 7.7.3 index enable flag (ixe) ....................................................................................................... 63 7.7.4 zero flag (z) and compare flag (cmp) .............................................................................. 63 7.7.5 carry flag (cy) ..................................................................................................................... 64 7.7.6 binary-coded decimal flag (bcd) ...................................................................................... 64 7.7.7 caution on use of arithmetic operations on the program status word ......................... 64 7.8 cautions on use of the system register ....................................................... 65 7.8.1 reserved words for use with the system register ......................................................... 65 7.8.2 handling of system register addresses fixed at 0 .......................................................... 67
C iii C chapter 8 general register (gr) ........................................................................................ 69 8.1 general register configuration ........................................................................ 69 8.2 functions of the general register .................................................................. 69 chapter 9 register file (rf) ................................................................................................... 71 9.1 register file configuration ................................................................................. 71 9.1.1 configuration of the register file ...................................................................................... 71 9.1.2 relationship between the register file and data memory .............................................. 71 9.2 functions of the register file ............................................................................ 72 9.2.1 functions of the register file ............................................................................................ 72 9.2.2 control register functions ................................................................................................. 72 9.2.3 register file manipulation instructions .............................................................................. 73 9.3 control register ....................................................................................................... 75 9.4 cautions on using the register file ................................................................. 75 9.4.1 concerning operation of the control register (read-only and unused registers) ........ 75 9.4.2 register file symbol definitions and reserved words .................................................... 76 chapter 10 data buffer (dbf) ................................................................................................ 79 10.1 data buffer configuration ................................................................................... 79 10.2 functions of the data buffer .............................................................................. 80 10.2.1 data buffer and peripheral hardware ................................................................................ 81 10.2.2 data transfer with peripheral hardware ............................................................................ 82 10.2.3 table reference .................................................................................................................. 83 chapter 11 arithmetic and logic unit ............................................................................. 85 11.1 alu block configuration ....................................................................................... 85 11.2 functions of the alu block .................................................................................. 85 11.2.1 functions of the alu .......................................................................................................... 85 11.2.2 functions of temporary registers a and b ....................................................................... 90 11.2.3 functions of the status flip-flop ......................................................................................... 90 11.2.4 performing operations in 4-bit binary ................................................................................ 91 11.2.5 performing operations in bcd ........................................................................................... 91 11.2.6 performing operations in the alu block ........................................................................... 93 11.3 arithmetic operations (addition and subtraction in 4-bit binary and bcd) ........................................................................................................... 94 11.3.1 addition and subtraction when cmp=0 and bcd=0 ......................................................... 95 11.3.2 addition and subtraction when cmp=1 and bcd=0 ......................................................... 95 11.3.3 addition and subtraction when cmp=0 and bcd=1 ......................................................... 95 11.3.4 addition and subtraction when cmp=1 and bcd=1 ......................................................... 96 11.3.5 cautions on use of arithmetic operations .......................................................................... 96 11.4 logical operations ................................................................................................... 96 11.5 bit judgement .............................................................................................................. 97 11.5.1 true (1) bit judgement ..................................................................................................... 98 11.5.2 false (0) bit judgement .................................................................................................... 98
C iv C 11.6 comparison judgement .......................................................................................... 99 11.6.1 equal to judgement ........................................................................................................ 100 11.6.2 not equal to judgement ................................................................................................. 100 11.6.3 greater than or equal to judgement ............................................................................. 101 11.6.4 less than judgement ..................................................................................................... 101 11.7 rotations ....................................................................................................................... 102 11.7.1 rotation to the right ........................................................................................................... 102 11.7.2 rotation to the left ............................................................................................................. 103 chapter 12 ports ........................................................................................................................ 105 12.1 port 0a (p0a 0 , p0a 1 , p0a 2 , p0a 3 ) ................................................................................. 105 12.2 port 0b (p0b 0 , p0b 1 , p0b 2 , p0b 3 ) .................................................................................. 106 12.3 port 0c (p0c 0 , p0c 1 , p0c 2 , p0c 3 ) ... in the case of the m pd17120 and 17121 ....... 107 12.4 port 0c (p0c 0 /cin 0 , p0c 1 /cin 1 , p0c 2 /cin 2 , p0c 3 /cin 3 ) in the case of the m pd17132, 17133, 17p132, and 17p133 ............................................................................................ 108 12.5 port 0d (p0d 0 /sck, p0d 1 /so, p0d 2 /si, p0d 3 /tmout) ............................................ 109 12.6 port 0e (p0e0, p0e1/v ref ) ... v ref , m pd17132, 17133, 17p132, and 17p133 only ....................................................................................................................... 111 12.6.1 cautions when operating port registers .......................................................................... 112 12.7 port control register ............................................................................................ 113 12.7.1 input/output switching by group i/o ................................................................................. 113 12.7.2 input/output switching by bit i/o ...................................................................................... 114 chapter 13 peripheral hardware ....................................................................................... 117 13.1 8-bit timer counter (tm) .......................................................................................... 117 13.1.1 8-bit timer counter configuration ...................................................................................... 117 13.1.2 8-bit timer counter control register ................................................................................. 119 13.1.3 operation of 8-bit timer counters ..................................................................................... 120 13.1.4 selecting count pulse ......................................................................................................... 120 13.1.5 setting a count value in modulo register and calculation method ................................ 121 13.1.6 margin of error of interval time ......................................................................................... 124 13.1.7 reading count register values .......................................................................................... 126 13.1.8 timer output ....................................................................................................................... 129 13.1.9 timer resolution and maximum setting time .................................................................. 130 13.2 comparator (mpd17132, 17133, 17p132, and 17p133 only) ............................. 131 13.2.1 configuration of comparator ............................................................................................... 131 13.2.2 functions of comparator ..................................................................................................... 132 13.3 serial interface (sio) ................................................................................................ 135 13.3.1 functions of the serial interface ........................................................................................ 135 13.3.2 3-wire serial interface operation modes ........................................................................... 137 13.3.3 setting values in the shift register ................................................................................... 141 13.3.4 reading values from the shift register ............................................................................. 142 13.3.5 program example of serial interface .................................................................................. 143
C v C chapter 14 interrupt functions ........................................................................................ 145 14.1 interrupt sources and vector address ......................................................... 146 14.2 hardware components of the interrupt control circuit .................... 147 14.2.1 interrupt request flag (irq ) and the interrupt enable flag (ip ) ........................... 147 14.2.2 ei/di instruction ................................................................................................................... 147 14.3 interrupt sequence .................................................................................................. 152 14.3.1 acceptance of interrupts .................................................................................................... 152 14.3.2 return from the interrupt routine ..................................................................................... 154 14.3.3 interrupt acceptance timing ............................................................................................... 155 14.4 program example of interrupt ........................................................................... 158 chapter 15 standby functions ........................................................................................... 161 15.1 outline of standby function ............................................................................... 161 15.2 halt mode ...................................................................................................................... 163 15.2.1 halt mode setting ............................................................................................................. 163 15.2.2 start address after halt mode is canceled ..................................................................... 163 15.2.3 halt setting condition ....................................................................................................... 165 15.3 stop mode ...................................................................................................................... 167 15.3.1 stop mode setting ............................................................................................................ 167 15.3.2 start address after stop mode cancellation .................................................................... 167 15.3.3 stop setting condition ...................................................................................................... 169 chapter 16 reset ........................................................................................................................ 171 16.1 reset functions .......................................................................................................... 171 16.2 resetting ........................................................................................................................ 172 16.3 power-on/power-down reset function .......................................................... 173 16.3.1 conditions required to enable the power-on reset function ......................................... 173 16.3.2 description and operation of the power-on reset function ........................................... 174 16.3.3 condition required for use of the power-down reset function .................................... 176 16.3.4 description and operation of the power-down reset function ...................................... 176 chapter 17 one-time prom writing/verifying ............................................................... 179 17.1 differences between mask rom version and one-time prom version ............................................................................................ 179 17.2 operating mode in program memory writing/verifying ......................... 180 17.3 writing procedure of program memory ........................................................ 181 17.4 reading procedure of program memory ........................................................ 182 chapter 18 instruction set .................................................................................................. 185 18.1 overview of the instruction set ....................................................................... 185 18.2 legend ............................................................................................................................. 18 6 18.3 list of the instruction set ................................................................................... 187 18.4 assembler (as17k) macro instructions .......................................................... 188
C vi C 18.5 instructions ................................................................................................................. 189 18.5.1 addition instructions ........................................................................................................... 189 18.5.2 subtraction instructions ...................................................................................................... 202 18.5.3 logical operation instructions ............................................................................................ 211 18.5.4 judgment instruction .......................................................................................................... 216 18.5.5 comparison instructions ..................................................................................................... 218 18.5.6 rotation instructions ........................................................................................................... 221 18.5.7 transfer instructions ........................................................................................................... 222 18.5.8 branch instructions ............................................................................................................. 239 18.5.9 subroutine instructions ....................................................................................................... 241 18.5.10 interrupt instructions ........................................................................................................... 247 18.5.11 other instructions ................................................................................................................ 249 chapter 19 assembler reserved words .......................................................................... 251 19.1 mask option pseudo instructions ..................................................................... 251 19.1.1 option and endop pseudo instructions ......................................................................... 251 19.1.2 mask option definition pseudo instructions ..................................................................... 252 19.2 reserved symbols ...................................................................................................... 254 19.2.1 list of reserved symbols ( m pd17120, 17121) .................................................................. 254 19.2.2 list of reserved symbols ( m pd17132, 17133, 17p132, 17p133) .................................... 260 appendix a development tools .......................................................................................... 267 appendix b ordering mask rom .......................................................................................... 269 appendix c cautions to take in system clock oscillation circuit configurations .................................................................................................. 271 appendix d instruction list ................................................................................................. 273 appendix e revision history ................................................................................................. 275
C vii C list of figures (1/2) figure no. title page 3-1 program counter ............................................................................................................. ...... 19 3-2 value of the program counter after an instruction is executed ............................................ 20 3-3 value in the program counter after reset ............................................................................. 20 3-4 value in the program counter during execution of a direct branch instruction .................... 20 3-5 value in the program counter during execution of an indirect branch instruction ................ 21 3-6 value in the program counter during execution of a direct subroutine call ......................... 21 3-7 value in the program counter during execution of an indirect subroutine call ..................... 21 3-8 value in the program counter during execution of a return instruction ............................... 22 4-1 program memory map for the m pd17120 subseries ............................................................ 23 4-2 direct subroutine call (call addr) ........................................................................................ 26 4-3 table reference (movt dbf, @ar) ..................................................................................... 27 5-1 configuration of data memory .............................................................................................. 31 5-2 system register configuration .............................................................................................. 3 2 5-3 data buffer configuration ................................................................................................... ... 32 5-4 general register (gr) configuration ..................................................................................... 33 5-5 port register configuration ................................................................................................. .. 33 6-1 stack configuration ......................................................................................................... ....... 35 7-1 allocation of system register in data memory ..................................................................... 41 7-2 system register configuration .............................................................................................. 4 2 7-3 address register configuration ............................................................................................. 4 3 7-4 address register used as a peripheral register ................................................................... 44 7-5 window register configuration ............................................................................................. 45 7-6 bank register configuration ................................................................................................. .46 7-7 index register and memory pointer configuration ............................................................... 48 7-8 data memory address modification by index register and memory pointer ....................... 48 7-9 example of operation when mpe=0 and ixe=0 ................................................................... 51 7-10 example of operation when mpe=1 and ixe=0 ................................................................... 53 7-11 example of operation when mpe=0 and ixe=1 ................................................................... 55 7-12 example of operation when mpe=0 and ixe=1 ................................................................... 57 7-13 example of operation when mpe=0 and ixe=1 (array processing) ..................................... 58 7-14 general register pointer configuration ................................................................................. 59 7-15 general register configuration ............................................................................................. .60 7-16 program status word configuration ...................................................................................... 61 7-17 outline of functions of the program status word ................................................................ 62 8-1 general register configuration .............................................................................................. 70 9-1 register file configuration ................................................................................................. ... 71 9-2 relationship between the register file and data memory ................................................... 72 9-3 accessing the register file using the peek and poke instructions .................................... 74 10-1 allocation of the data buffer .............................................................................................. ... 79 10-2 data buffer configuration .................................................................................................. .... 80 10-3 relationship between the data buffer and peripheral hardware .......................................... 80 11-1 configuration of the alu ................................................................................................... .... 86 12-1 changes in port register due to execution of the clr1 p0e1 instruction ............................. 112 12-2 input/output switching by group i/o .................................................................................... 113 12-3 bit i/o port control register .............................................................................................. .... 114
C viii C list of figures (2/2) figure no. title page 13-1 configuration of the 8-bit timer counter ............................................................................... 118 13-2 timer mode register ........................................................................................................ ..... 119 13-3 setting the count value in a modulo register ....................................................................... 122 13-4 error in zero-clearing the count registe during counting .................................................... 124 13-5 error in starting counting from the count halt state ............................................................ 125 13-6 reading 8-bit counter count values ..................................................................................... 127 13-7 timer output control mode register .................................................................................... 129 13-8 configuration of comparator ................................................................................................ . 131 13-9 comparator input channel selection register ....................................................................... 133 13-10 reference voltage selection register ................................................................................... 133 13-11 comparator operation control register ................................................................................ 134 13-12 block diagram of the serial interface .................................................................................... 1 36 13-13 timing of 8-bit transmission and reception mode (simultaneous transmission reception) ................................................................................ 137 13-14 timing of the 8-bit reception mode ..................................................................................... 138 13-15 serial interface control register ......................................................................................... ... 139 13-16 setting a value in the shift register ..................................................................................... . 141 13-17 reading a value from the shift register ................................................................................ 142 14-1 interrupt control register ................................................................................................. ..... 148 14-2 interrupt handling procedure ............................................................................................... .. 153 14-3 return from interrupt handling ............................................................................................. . 154 14-4 interrupt acceptance timing chart (when inte=1 and ip =1) ......................................... 155 15-1 cancellation of halt mode .................................................................................................. . 164 15-2 cancellation of stop mode .................................................................................................. . 168 16-1 reset block configuration .................................................................................................. ... 172 16-2 resetting .................................................................................................................. ............. 172 16-3 example of the power-on reset operation .......................................................................... 175 16-4 example of the power-down reset operation ..................................................................... 177 16-5 example of reset operation during the period from power-down reset to power recovery ................................................................................................................. ... 178 17-1 procedure of program memory writing ................................................................................. 182 17-2 procedure of program memory reading ............................................................................... 183 19-1 configuration of control register ( m pd17120, 17121) .......................................................... 258 19-2 configuration of control register ( m pd17132, 17133, 17p132, 17p133) .............................. 264 c-1 externally installed system clock oscillation circuit ............................................................. 271 c-2 unsatisfactory oscillation circuit examples .......................................................................... 272
C ix C list of tables (1/1) table no. title page 2-1 handling unused pins ........................................................................................................ .... 17 4-1 vector address for the m pd17120 subseries ........................................................................ 25 6-1 operation of the stack pointer .............................................................................................. 37 6-2 operation of the stack pointer during execution .................................................................. 38 6-3 stack operation during table reference ............................................................................... 38 6-4 stack operation during interrupt receipt and return ............................................................ 39 6-5 stack operation during the push and pop instructions ...................................................... 39 7-1 address-modified instruction statements ............................................................................. 49 7-2 zero flag (z) and compare flag (cmp) .................................................................................. 63 10-1 peripheral hardware ........................................................................................................ ...... 81 11-1 list of alu instructions ................................................................................................... ...... 88 11-2 results of arithmetic operations performed in 4-bit binary and bcd .................................. 92 11-3 types of arithmetic operations ............................................................................................. 94 11-4 logical operations ......................................................................................................... ........ 97 11-5 table of true values for logical operations .......................................................................... 97 11-6 bit judgement instructions ................................................................................................. .. 97 11-7 comparison judgement instructions ..................................................................................... 99 12-1 writing into and reading from the port register (0.70h) ...................................................... 105 12-2 writing into and reading from the port register (0.71h) ...................................................... 106 12-3 writing/reading to/from port register (0.72h) ( m pd17120, 17121) ....................................... 107 12-4 writing into and reading from the port register (0.72h) and pin function selection ........... 108 12-5 register file contents and pin functions .............................................................................. 110 12-6 contents read from the port register (0.73h) ...................................................................... 110 12-7 writing into and reading from the port registers (0.6fh.0, 0.6fh.1) ................................... 111 13-1 timer resolution and maximum setting time ...................................................................... 130 13-2 list of serial clock ....................................................................................................... .......... 135 13-3 serial interfaces operation mode ......................................................................................... 1 37 14-1 interrupt source types ..................................................................................................... ..... 146 14-2 interrupt request flag and interrupt enable flag .................................................................. 147 15-1 states during standby mode ................................................................................................. 162 15-2 halt mode cancellation condition ....................................................................................... 163 15-3 start address after halt mode cancellation ....................................................................... 163 15-4 stop mode cancellation condition ....................................................................................... 167 15-5 start address after stop mode cancellation ....................................................................... 167 16-1 state of each hardware unit when reset ............................................................................ 171 17-1 pins used for writing/verifying program memory ................................................................ 179 17-2 differences between mask rom version and one-time prom version ............................ 180 17-3 operating mode setting ..................................................................................................... ... 180 19-1 mask option definition pseudo instructions ......................................................................... 252
C x C [memo]
chapter 1 general the m pd17120, 17121, 17132 and 17133 are 4-bit single-chip microcontrollers employing the 17k architecture and containing 8-bit timer (1 channel), 3-wire serial interface, and power-on/power-down reset circuit. the m pd17p132 and 17p133 are the one-time prom version of the m pd17132 and 17133, respectively, and are suitable for program evaluation at system development and for small-scale production. the following are features of the m pd17120 subseries. ? comparator input ( m pd17132, 17133, 17p132, 17p133 only) . comparison function with external reference voltage (v ref ) . can be used as 4-bit a/d converter by using 15 types of internal reference voltage (1/16 to 15/16 v dd ) depending on the software ? 3-wire serial interface: 1 channel ? power-on/power-down reset circuit (reducing external circuits) ? m pd17p132 and 17p133 can operate in the same way as mask rom version . v dd = 2.7 to 5.5 v these features of the m pd17120 subseries are suitable for use as a controller or a sub-microcomputer device in the following application fields; ? electric fan ? hot plate ? audio equipment ? mouse ? printer ? plain paper copier 1
chapter 1 general 2 operating supply voltage 1.1 function list item m pd17120 m pd17132 m pd17p132 m pd17121 m pd17133 m pd17p133 product name masked rom one-time prom masked rom one-time prom rom capacity 1.5k bytes 2k bytes 1.5k bytes 2k bytes (768 16 bits) (1024 16 bits) (768 16 bits) (1024 16 bits) ram capacity 64 4 bits 111 4 bits 64 4 bits 111 4 bits stack 5 address stacks; 1 interrupt stack ? 18 input/output ports input/output port count 19 ports ? 1 sense input (int pin note ) comparator 4-channel 4-channel (supply voltage) (v dd = 2.7 to 5.5 v) (v dd = 2.7 to 5.5 v) timer 1-channel (8-bit timer) serial interface 1-channel (3-wire) detection of the rising edge ? 1 external interrupt (int): detection of the trailing edge selectable interrupt detection of both rising and trailing edges ? timer (tm) ? serial interface (sio) system clock rc oscillation ceramic oscillation instruction execution time 8 m s (when f cc = 2 mhz) 2 m s (when f x = 8 mhz) standby function halt, stop power-on/power-down incorporated incorporated reset circuit (can be used on an applied circuit (can be used on an applied circuit of v dd =5 v 10%) of v dd =5 v 10%; f x = 400 khz to 4 mhz) ? 2.7 to 5.5 v ? 4.5 to 5.5 v (when using the power-on power/down reset function) ? 24-pin plastic shrink dip (300 mil) ? 24-pin plastic sop (375 mil) one-time prom product m pd17p132 C m pd17p133 C note when not using the external interrupt function, the int pin can be used as an input-only pin (sense input). as a sense input, the pin status is read not by the port register but by the control register's int flag. caution despite a high level of functional compatibility with the masked rom product, the prom product is different in terms of the internal rom circuit and some electric features. when switching from a prom to a masked rom product, be sure to sufficiently evaluate the application of the masked rom product based on its sample. none none ? 2 internal interrupts package
chapter 1 general 3 1.2 ordering information part number package internal rom m pd17120cs- 24-pin plastic shrink dip (300 mil) mask rom m pd17120gt- 24-pin plastic sop (375 mil) mask rom m pd17121cs- 24-pin plastic shrink dip (300 mil) mask rom m pd17121gt- 24-pin plastic sop (375 mil) mask rom m pd17132cs- 24-pin plastic shrink dip (300 mil) mask rom m pd17132gt- 24-pin plastic sop (375 mil) mask rom m pd17133cs- 24-pin plastic shrink dip (300 mil) mask rom m pd17133gt- 24-pin plastic sop (375 mil) mask rom m pd17p132cs 24-pin plastic shrink dip (300 mil) one-time prom m pd17p132gt 24-pin plastic sop (375 mil) one-time prom m pd17p133cs 24-pin plastic shrink dip (300 mil) one-time prom m pd17p133gt 24-pin plastic sop (375 mil) one-time prom remark : rom code number
chapter 1 general 4 1.3 block diagram ? block diagram of the m pd17120 and 17121 remark the terms cmos and n-ch in parentheses indicate the output form of the port. cmos: cmos push-pull output n-ch: n-channel open-drain output (each pin can contain pull-up resistor as specified using a mask option.) p0b 0 p0b 1 p0b 2 p0b 3 p0b (cmos) p0a 0 p0a 1 p0a 2 p0a 3 p0a (cmos) p0c 0 p0c 1 p0c 2 p0c 3 p0c (cmos) p0e 0 p0e 1 p0e (n-ch) alu instruction decoder rom 768 16 bits program counter stack 5 10 bits interrupt controller timer irqtm irqsio f x /2 n clock divider system clock generator x in x out p0d 0 /sck p0d 1 /so p0d 2 /si p0d 3 /tmout int f x /2 n cpu clk clk stop v dd power on/ power-down reset reset gnd rf ram 64 4 bits system reg. irqtm p0d (n-ch) irqsio serial i/o tm
chapter 1 general 5 ? block diagram of m pd17132, 17133, 17p132, and 17p133 remark the terms cmos and n-ch in parentheses indicate the output form of the port. cmos: cmos push-pull output n-ch: n-channel open-drain output (each pin can contain pull-up resistor as specified using a mask option.) note the devices in parentheses are effective only in the case of program memory write/verify mode of the m pd17p132 and m pd17p133. p0b 0 p0b 1 p0b 2 p0b 3 p0b (cmos) p0a 0 p0a 1 p0a 2 p0a 3 p0a (cmos) p0c 0 /cin 0 p0c 1 /cin 1 p0c 2 /cin 2 p0c 3 /cin 3 p0c (cmos) compa- rator alu instruction decoder rom 1024 16 bits program counter stack 5 10 bits interrupt controller timer irqtm irqsio f x /2 n clock divider system clock generator x in (clk) note x out p0d 0 /sck p0d 1 /so p0d 2 /si p0d 3 /tmout int (v pp ) note f x /2 n cpu clk clk stop v dd power on/ power-down reset reset gnd rf ram 111 4 bits system reg. irqtm p0d (n-ch) irqsio serial interface tm p0e (n-ch) p0e 0 p0e 1 /v ref
chapter 1 general 6 1.4 pin configuration (top view) (1) normal operating mode 24-pin plastic shrink dip 24-pin plastic sop notes 1. there is no v ref pin for the m pd17120 and 17121. 2. pins cin 0 to cin 3 do not exist in the m pd17120 and 17121. gnd x in x out reset p0a 0 p0a 1 p0a 2 p0a 3 p0b 0 p0b 1 p0b 2 p0b 3 v dd p0e 1 /v ref note 1 p0e 0 p0d 3 / tmout p0d 2 /si p0d 1 /so p0d 0 /sck int p0c 3 /c in3 note 2 p0c 2 /c in2 note 2 p0c 1 /c in1 note 2 p0c 0 /c in0 note 2 m pd17120cs- , pd17120gt- pd17121cs- , pd17121gt- pd17132cs- , pd17132gt- pd17133cs- , pd17133gt- pd17p132cs, pd17p132gt pd17p133cs, pd17p133gt 1 2 3 4 5 6 7 8 9 10 11 12 24 23 22 21 20 19 18 17 16 15 14 13 m mm mm mm mm mm
chapter 1 general 7 (2) program memory write/verify mode caution ( ) represents processing of the pins which are not used in program memory write/verify mode. l : connect to gnd via pull-down resistor one by one. open : this pin should not be connected. (3) pin name cin 0 to cin 3 : comparator input clk : clock input for address verification d 0 to d 7 : data input/output gnd : ground int : external interrupt input md 0 to md 3 : operating mode selection p0a 0 to p0a 3 : port 0a p0b 0 to p0b 3 : port 0b p0c 0 to p0c 3 : port 0c p0d 0 to p0d 3 : port 0d p0e 0 to p0e 3 : port 0e reset : reset input sck : serial clock input/output si : serial data input so : serial data output tmout : timer output v dd : power supply v pp : programming voltage supply v ref : external reference voltage x in , x out : system clock oscillation gnd clk open (l) md 0 md 1 md 2 md 3 d 0 d 1 d 2 d 3 v dd v pp d 7 d 6 d 5 d 4 m pd17p132cs pd17p132gt pd17p133cs pd17p133gt 1 2 3 4 5 6 7 8 9 10 11 12 24 23 22 21 20 19 18 17 16 15 14 13 m m m ? ? ? ? ? ? ? ? ? (l)
[memo] 8
CC chapter 2 pin functions 2.1 pin functions 2.1.1 pins in normal operation mode output at power- pin no. symbol function format on/reset 1 gnd grounded C C 2x in m pd17121, 17133, 17p133 3x out ?x in , x out . pins for system clock resonator oscillation . connected to ceramic resonator 2 osc 1 m pd17120, 17132, 17p132 3 osc 0 ? osc 0 , osc 1 . pins for system clock oscillation . resistor is connected between osc 0 and osc 1 4 reset system reset input C input pull-up resistor can be incorporated by mask option note 5 p0a 0 port 0a cmos input || . 4-bit i/o port push-pull 8 p0a 3 . input/output can be set by each bit 9 p0b 0 port 0b cmos input || . 4-bit i/o port push-pull 12 p0b 3 . input/output can be set by 4-bit unit 13 p0c 0 /cin 0 port 0c and analog voltage input of comparator cmos input | | ? p0c 0 to p0c 3 push-pull (p0c) 16 p0c 3 /cin 3 . 4-bit i/o port . input/output can be set by each bit ? cin 0 to cin 3 ( m pd17132, 17133, 17p132, 17p133 only) . analog input of comparator 17 int external interrupt request signal input and sense input C input note the m pd17p132 and 17p133 have no pull-up resistor by mask option. 9
chapter 2 pin functions 10 output at power- pin no. symbol function format on/reset 18 p0d 0 /sck port 0d, output of timer, serial data input, serial data n-ch input output, serial clock input/output open drain (p0d) ? p0d 0 to p0d 3 . 4-bit i/o port . input/output can be set per bit . pull-up resistor can be incorporated by each bit by mask option note ? sck . serial clock input/output 19 p0d 1 /so ? so . serial data output 20 p0d 2 /si ? si . serial data input 21 p0d 3 /tmout ? tmout . output of timer 22 p0e 0 port 0e and reference voltage input of comparator n-ch input 23 p0e 1 /v ref ? p0e 0 , p0e 1 open drain (p0e) . 2-bit i/o port . input/output can be set by each bit . pull-up resistor can be incorporated per bit by mask option note ?v ref ( m pd17132,17133, 17p132, 17p133 only) . external reference voltage input of comparator 24 v dd positive power supply C C note the m pd17p132 and 17p133 have no pull-up resistor by mask option.
chapter 2 pin functions 11 2.1.2 pins in program memory write/verify mode ... m pd17p132, 17p133 only pin no. symbol function i/o 1 gnd grounded C 2 clk clock input for address updating in program memory writing/verifying input 5md 0 | | input for selecting operation mode in program memory writing/verifying input 8 md 3 9d 0 | | 8-bit data input/output in program memory writing/verifying input/output 12 d 7 17 v pp pin for applying programming voltage in program memory C writing/verifying apply +12.5 v 24 v dd positive power supply C apply +6 v in program memory writing/verifying.
chapter 2 pin functions 12 2.2 pin input/output circuit below are simplified diagrams of the input/output circuits for each pin of the m pd17120 subseries. (1) p0a 0 -p0a 3 , p0b 0 -p0b 3 data output disable selector p-ch n-ch v dd input buffer output latch
chapter 2 pin functions 13 (2) p0c 0 /cin 0 -p0c 3 /cin 3 note note pins cin 0 to cin 3 are not included in the m pd17120 and 17121. data output disable selector p-ch n-ch v dd input buffer output latch input disable analog (comparator) input
chapter 2 pin functions 14 (3) p0d 0 -p0d 3 note the m pd17p132 and 17p133 have no pull-up resistor by mask option, and are always open. (4) p0e 0 note the m pd17p132 and 17p133 have no pull-up resistor by mask option, and are always open. data output disable selector n-ch v dd input buffer output latch mask option note data output disable n-ch v dd input buffer output latch mask option note
chapter 2 pin functions 15 (5) p0e 1 /v ref note1 notes 1. the m pd17120 and 17121 have no v ref pin function. 2. the m pd17p132 and 17p133 have no pull-up resistor by mask option, and are always open. (6) int data v ref enable n-ch v dd output latch mask option note 2 selector input buffer v ref output disable input buffer
chapter 2 pin functions 16 (7) reset note the m pd17p132 and 17p133 have no pull-up resistor by mask option, and are always open. input buffer v dd mask option note
chapter 2 pin functions 17 2.3 handling unused pins in normal operation mode, it is recommended to process the unused pins as follows: table 2-1. handling unused pins recommended measures inside microcontroller outside microcontroller p0a, p0b, p0c C does not incorporate a pull-up resistor by the mask option incorporates a pull-up resistor by the mask option. p0a, p0bp0c (cmos port) outputs low level without incorporating pull-up resistor by the mask option. outputs high level with a pull-up resistor incorporated by the mask option. external interrupt (int) note2 C directly connected to gnd does not incorporate a pull-up resistor by the mask option incorporates a pull-up resistor by the mask option. notes 1. when externally pulling up (connecting to v dd through a resistor) or pulling down (connecting to the gnd through a resistor), make sure to pay attention to the port's driving ability and current consumption. when pulling up or pulling down at a high resistance value, be careful to ensure that no noise is caused in the relevant pin. although it depends on the applied circuit as well, it is usual to choose several tens of k w as the resistance value for pull-up or pull-down. 2. the int pin is for the test mode setting function as well; connect it directly to the gnd when unused. 3. if the applied circuit requires a high level of reliability, be sure to design it so that the reset signal is input externally. also, since the reset pin is for the test mode setting function as well, connect it directly to the v dd when unused. caution the output levels of the input/output mode and pins are recommended to be fixed by being set repeatedly in their respective loops in the program. remark the m pd17p132 and 17p133 do not contain pull-up resistors by the mask option. each pin is connected to v dd or gnd through the resistor. note1 open pin name input mode p0d, p0e C port output mode open p0d and p0e (n-ch open drain port) reset note3 when using only the built-in power-on/power-down reset directly connected to v dd
chapter 2 pin functions 18 2.4 cautions on use of the reset and int pins (in normal operation mode only) in addition to the function described in 2.1 pin functions , the reset pin and the int pin have the function (for ic testing only) of setting test mode for testing the internal operation of the m pd17120 subseries. if a voltage exceeding the v dd is applied to either of these pins, test mode is set. therefore, adding a noise exceeding v dd even in normal operation may result in placing the pin in test mode, thus impeding normal operation. for example, if the reset or int pin wires are laid out too long, wiring noise is added to these pins, thus causing the above problem. therefore, make sure that the wires are laid down in such a manner that such inter-wire noises are suppressed as much as possible. if noise is still a problem, take noise countermeasures based on external parts as shown in the illustrations below. ? connecting a diode of small v f between v dd s ? connecting a capacitor between v dd s v dd reset, int v dd diode whose v f is small v dd reset, int v dd
chapter 3 program counter (pc) the program counter is used to specify an address in program memory. 3.1 program counter configuration figure 3-1 shows the configuration of the program counter. the program counters are 10-bit binary counters. this program counter is incremented whenever an instruction is executed. figure 3-1. program counter 3.2 program counter operation normally, the program counter is automatically incremented each time a command is executed. the memory address at which the next instruction to be executed is stored is assigned to the program counter under the following conditions: at reset; when a branch, subroutine call, return, or table referencing instruction is executed; or when an interrupt is received. sections 3.2.1 to 3.2.7 explain program counter operating during execution of each instruction. msb pc9 pc pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 lsb 19
chapter 3 program counter (pc) 20 figure 3-2. value of the program counter after an instruction is executed program counter bit program counter value instruction pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 during reset 0 0 0 0 0 0 0 0 0 0 br addr call addr br @ar call @ar value in the address register (ar) (movt dbf, @ar) ret retsk reti during interrupt each interrupted vector address 3.2.1 program counter at reset by setting the reset terminals to low, the program counter is set to 000h. figure 3-3. value in the program counter after reset value set by addr value in the address stack register location pointed to the stack pointer (return address) msb 0 all bits are set to 0 000000000 lsb 3.2.2 program counter during execution of the branch instruction (br) there are two ways to specify branching using the branch instruction. one is to specify the branch address in the operand using the direct branch instruction (br addr). the other is to branch to the address specified by the address register using the indirect branch instruction (br @ar). the address specified by a direct branch instruction is placed in the program counter. figure 3-4. value in the program counter during execution of a direct branch instruction msb pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 lsb address specified by addr an indirect branch instruction causes the address in the address counter to be placed in the program counter.
chapter 3 program counter (pc) 21 figure 3-5. value in the program counter during execution of an indirect branch instruction msb pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 lsb ar9 ar8 ar7 ar6 ar5 ar4 ar3 ar2 ar1 ar0 3.2.3 program counter during execution of subroutine calls (call) there are two ways to specify branching using subroutine calls. one is to specify the branch address in the operand using the direct subroutine call (call addr). the other is to branch to the address specified by the address register using the indirect subroutine call (call @ar). a direct subroutine call causes the value in the program counter to be saved in the stack and then the address specified in the operand to be placed in the program counter. direct subroutine calls can specify any address in program memory. figure 3-6. value in the program counter during execution of a direct subroutine call an indirect subroutine call causes the value in the program counter to be saved in the stack and then the value in the address register to be placed in the program counter. figure 3-7. value in the program counter during execution of an indirect subroutine call msb pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 lsb address specified by addr msb pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 lsb ar9 ar8 ar7 ar6 ar5 ar4 ar3 ar2 ar1 ar0 address stack register n (n = 0 to 4)
chapter 3 program counter (pc) 22 3.2.4 program counter during execution of return instructions (ret, retsk, reti) during execution of a return instruction (ret, retsk, reti), the program counter is restored to the value saved in the address stack register. figure 3-8. value in the program counter during execution of a return instruction 3.2.5 program counter during table reference (movt) during execution of table reference (movt dbf, @ar), the value in the program counter is saved in the stack, the address register is set by the program counter, then the contents stored at that program memory location is read into the data buffer (dbf). after the program memory contents are read into dbf, the program counter is restored to the value saved in the address stack register. caution one level of the address stack is temporarily used during execution of table reference. be careful of the stack level. 3.2.6 program counter during execution of skip instructions (ske, skge, sklt, skne, skt skf) when skip conditions are met and a skip instruction (ske, skge, sklt, skne, skt, skf) is executed, the instruction immediately following the skip instruction is treated as a no operation instruction (nop). therefore, whether skip conditions are met or not, the number of instructions executed and instruction execution time remain the same. 3.2.7 program counter when an interrupt is received when an interrupt is received, the value in the program counter is saved in the address stack. next, the vector address for the interrupt received is placed in the program counter. 3.3 cautions on program counter operation consisting of 10 bits, the m pd17120/17121's program counter (pc) can specify a program of up to 1024 steps. as opposed to this, the rom size is only 768 steps (addresses 0000h-02ffh). if the program counter's value exceeds 300h, the contents of the program are equivalent to reading ffffh and executing the "skf psw, #0fh" instruction. therefore, be careful about the following point: (1) when the instruction at the 768th step (address 02ffh) is executed, it does not automatically happen that the program counter goes to 0000h. if the instruction up to the 768th step (address 02ffh) is other than a branch (br) or (ret) instruction, it will result in specifying a program counter not contained in a rom. be careful about this. (2) in the same manner as (1), please avoid using an instruction that will branch to after the 768th step (address 02ffh). msb pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0 lsb address stack register n (n = 0 to 4)
chapter 4 program memory (rom) the program configuration of the m pd17120 subseries is as follows. product name program memory capacity program memory address m pd17120 m pd17121 m pd17132 m pd17133 m pd17p132 m pd17p133 program memory stores the program, and the constant data table. the top of the program memory is allocated to the reset start address and the interrupted vector address. the program memory address is specified by the program counter. 4.1 program memory configuration figure 4-1 shows the program memory map. branch instructions, subroutine calls, and table references can specify any address in program memory (0000h - 07ffh). figure 4-1. program memory map for the m pd17120 subseries 1.5k bytes (768 16 bits) 0000h-02ffh 2k bytes (1024 16 bits) 0000h-03ffh reset start address serial interface interrupt vector timer interrupt vector external (int) interrupt vector ( pd17120/17121) ( pd17132/17133/17p132/17p133) m m 16 bits 0000h 0001h 0002h 0003h address 02ffh 03ffh subroutine entry address for the call addr instruction branch address for the br addr instruction branch address for the br @ar instruction subroutine entry address for the call @ar instruction table reference address for the movt dbf, @ar instruction 23
chapter 4 program memory (rom) 24 4.2 program memory usage program memory has the following two main functions: (1) storage of the program (2) storage of constant data the program is made up of the instructions which operate the cpu (central processing unit). the cpu executes sequential processing according to the instructions stored in the program. in other words, the cpu reads each instruction in the order stored by the program in program memory and executes it. since all instructions are 16-bit long words, each instruction is stored in a single location in program memory. constant data, such as display output patterns, are set beforehand. the movt instruction is used to transfer data from program memory to the data buffer (dbf) in data memory. reading the constant data in program memory is called table reference. program memory is read-only (rom: read only memory) and therefore cannot be changed by any instructions. 4.2.1 flow of the program the program is usually stored in program memory starting from memory location 0000h and executed sequentially one memory location at a time. however, if for some reason a different kind of program is to be executed, it will be necessary to change the flow of the program. in this case, the branch instruction (br instruction) is used. if the same section of program code is going to appear in a number of places, reproducing the code each time it needs to be used will decrease the efficiency of the program. in this case, this section of program code should be stored in only one place in memory. then, by using the call instruction, this piece of code can be executed or read as many times as needed within the program. such a piece of code is called a subroutine. as opposed to a subroutine, code used during normal operation is called the main routine. for cases completely unrelated to the flow of the program (in which a section of code is to be executed when a certain condition arises), the interrupt function is used. whenever a condition arises that is unrelated to the flow of the program, the interrupt function can be used to branch the program to a prechosen memory location (called a vector address). items (1) to (5) explain branching of the program using the interrupt function and cpu instructions. (1) vector address table 4-1 shows the address to which the program is branched (vector address) when a reset or interrupt occurs.
chapter 4 program memory (rom) 25 table 4-1. vector address for the m pd17120 subseries vector address interrupt sources 0000h reset 0001h serial interface interrupt 0002h timer interrupt 0003h external interrupt (int pin) (2) direct branch when executing a direct branch (br addr), the 11-bit instruction operand is used to specify an address in program memory. (however, the most significant bit must be 0. if an address is specified outside of this range, an error will occur in the assembler.) a direct branch instruction can be used to branch to any address in program memory. (3) indirect branch when executing an indirect branch (br @ar), the program branches to the address specified by the value stored in the address register (ar). an indirect branch can be used to branch to any address in program memory. also refer to 7.2 address register (ar) . (4) direct subroutine call when using a direct subroutine call (call addr), the 11-bit instruction operand is used to specify a program memory address of the called subroutine. (however, the most significant bit must be 0. if an address is specified outside of this range, an error will occur in the assembler).
chapter 4 program memory (rom) 26 example figure 4-2. direct subroutine call (call addr) call sub1 program memory ret sub1: adddress 0000h 03ffh note note the last address of the program memory of the m pd17120 and m pd17121 is 02ffh. (5) indirect subroutine call when using an indirect subroutine call (call @ar), the value in the address register (ar) should be an address of the called subroutine. this instruction can be used to call any address in program memory. also refer to 7.2 address register (ar) .
chapter 4 program memory (rom) 27 4.2.2 table reference table reference is used to reference constant data in program memory. the table reference instruction (movt dbf, @af) is used to store the contents of the program memory address specified by the address register in the data buffer. since each location in program memory contains 16 bits of information, the movt instruction causes 16 bits of data to be stored in the data buffer. the address register can be used to table reference any location in program memory. caution note that one level of the stack is temporarily used when performing table reference. also refer to 7.2 address register (ar) and chapter 10 data buffer (dbf). remark as an exception, execution of table reference instructions requires two instruction cycle. figure 4-3. table reference (movt dbf, @ar) b 3 b 2 b 1 b 0 dbf3 b 3 b 2 b 1 b 0 dbf2 b 3 b 2 b 1 b 0 dbf1 b 3 b 2 b 1 b 0 dbf0 data buffer b 15 b 14 b 13 b 12 b 11 b 10 b 9 b 8 b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0 program memory b 3 b 2 b 1 b 0 ar3 b 3 b 2 b 1 b 0 ar2 b 3 b 2 b 1 b 0 ar1 b 3 b 2 b 1 b 0 ar0 address register 16-bit data read 000000 table addressing constant data
chapter 4 program memory (rom) 28 (1) constant data table example 1 shows an example of code used to reference a constant data table. example 1. code used for reading the values recorded in a constant data table. the value specified by an offset value is read. offset mem 0.00h ; storing area for the offset address. ; bank0 mov rph,#0 ; register pointer 7 is used to specify that mov rpl,#7 shl 1 ; operation results be stored in row address 7. romref: ; bank0 ; stores the start address of the constant data ; table in the address register (ar). mov ar3, #.dl.table shr 12 and 0fh mov ar2, #.dl.table shr 8 and 0fh mov ar1, #.dl.table shr 4 and 0fh mov ar0, #.dl.table and 0fh add ar0, offset ; adds the offset address. addc ar1, #0 addc ar2, #0 addc ar3, #0 movt dbf, @ar ; executes the table reference instruction. table: dw 0001h dw 0002h dw 0004h dw 0008h dw 0010h dw 0020h dw 0040h dw 0080h dw 0100h dw 0200h dw 0400h dw 0800h dw 1000h dw 2000h dw 4000h dw 8000h end
chapter 4 program memory (rom) 29 (2) branch table example 2 shows an example of code used to reference a branch table. example 2. code used for reading the values recorded in a branch table. the value specified by an offset value is read. offset mem 0.00h ; storing area for the offset address. ; bank0 mov rph,#0 ; sets the register pointer to row mov rpl,#7 shl 1 ; address 7. romref: ; bank0 ; stores the start address of the constant data ; table in the address register (ar). mov ar3, #.dl.table shr 12 and 0fh mov ar2, #.dl.table shr 8 and 0fh mov ar1, #.dl.table shr 4 and 0fh mov ar0, #.dl.table and 0fh add ar0, offset ; adds the offset address. addc ar1, #0 movt dbf, @ar ; executes the table reference instruction. put ar, dbf br @ar table: dw 0001h dw 0002h dw 0004h dw 0008h dw 0010h dw 0020h dw 0040h dw 0080h dw 0100h dw 0200h end
[memo] 30
chapter 5 data memory (ram) data memory stores data such as operation and control data. data can be read from or written to data memory with an instruction during normal operation. 5.1 data memory configuration figure 5-1 shows the configuration of data memory. data memory is controlled by the concept called banks. the m pd17120 subseries has bank0 only. an address is allocated to the data memory for each bank. an address consists of four bits of memory called "a nibble". the address of data memory consists of 7 bits. the three high-order bits are called "the row address", and the four low-order bits are called "the column address". for example, when the address of data memory is 1ah (0011010b), the row address is 1h (001b), and the column address is ah (1010b). in the case of the m pd17120 and 17121, addresses 40h to 6eh should not be used because they are non-mounted areas. sections 5.1.1 to 5.1.6 describe functions of data memory other than its use as address space. figure 5-1. configuration of data memory 0 1 2 3 4 5 6 7 0123456789abcdef dbf3 dbf2 dbf1 dbf0 p0e (2 bits) p0a 4 bits p0b 4 bits p0c 4 bits p0d 4 bits system register example: address 1ah of bank0 bank0 remark the shaded parts represent the non-mounted area in the case of the m pd17120 and 17121. 31
chapter 5 data memory (ram) 32 5.1.1 system register (sysreg) the system register (sysreg) consists of the 12 nibbles allocated at addresses 74h to 7fh in data memory. the system register (sysreg) is allocated independently of the banks. this means that each bank has the same system register at addresses 74h to 7fh. figure 5-2 shows the configuration of the system register. figure 5-2. system register configuration system register (sysreg) address 74h 75h 76h 77h 78h 79h 7ah 7bh 7ch 7dh 7eh 7fh index register (ix) data memory row address pointer (mp) name (symbol) address register (ar) window register (wr) bank register (bank) general register pointer (rp) program status word (psword) 5.1.2 data buffer (dbf) the data buffer consists of four nibbles allocated at addresses 0ch to 0fh in bank0 of data memory. figure 5-3 shows the configuration of the data buffer. figure 5-3. data buffer configuration data buffer (dbf) address 0ch 0dh 0eh 0fh symbol dbf3 dbf2 dbf1 dbf0 5.1.3 general register (gr) the general register consists of 16 nibbles specified by an arbitrary row address in a bank in data memory. this arbitrary row address in a bank is pointed to by the register pointer (rp) in the system register (sysreg). in the case of the m pd17120 and 17121, addresses 40h to 6eh are non-mounted areas. these areas should not be specified as a general register. figure 5-4 shows the configuration of the general register (gr).
chapter 5 data memory (ram) 33 5.1.4 port registers a port register consists of five nibbles allocated at addresses 6fh to 73h in bank0 of the data memory. as shown in figure 5-5, the two high-order bits of address 6fh are always set to 0. figure 5-5 shows the configuration of the port registers. figure 5-5. port register configuration port register address 6fh 70h 71h 72h 73h p0e p0a p0b p0c p0d pppppppppppppppppp 000000000000000000 eeaaaabbbbcccc dddd 103210321032103210 5.1.5 general data memory general data memory is all the data memory not used by the port and system registers (sysreg). in other words, general data memory consists of 64 nibbles ( m pd17120 and 17121) or 111 nibbles ( m pd17132, 17133, 17p132, and 17p133). 5.1.6 uninstalled data memory there is no hardware installed at addresses 40h to 6eh of the m pd17120 and 17121. any attempt to read this area will yield unpredictable results. writing data to this area is invalid and should therefore not be attempted. figure 5-4. general register (gr) configuration symbol 00 bank0 area specifiable as general register 0 1 2 3 4 5 6 7 0123456789abcdef bank0 port register row address column address sysreg general register pointed to by general register pointer (rp) in system register. note that row addresses 4 to 6 in the case of the pd17120 and 17121 are uninstalled mem- ory locations. the register pointer (rp) should therefore not specify a row address in this area. m
[memo] 34
chapter 6 stack the stack is a register used to save information such as the program return address and the contents of the system register during execution of subroutine calls, interrupts and similar operations. 6.1 stack configuration figure 6-1 shows the stack configuration. the stack consists of the following parts: one 3-bit binary counter stack pointer, five 10-bit address stack registers, and one 5-bit interrupt stack registers. figure 6-1. stack configuration b 9 address stack register (asr) b 8 b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0 b 10 address stack register 0 address stack register 1 address stack register 2 address stack register 3 address stack register 4 0h 1h 2h 3h 4h b 2 spb 2 b 1 spb 1 b 0 spb 0 stack pointer (sp) bcdsk interrupt stack register (intsk) cmpsk cysk zsk ixesk 0h 6.2 functions of the stack the stack is used to save the return address during execution of subroutine calls and table reference instructions. when an interrupt occurs, the program return address and the program status word (psword) are automatically saved in the stack. remark all the 5 bits of psword are automatically cleared to zero after being saved in the interrupt stack register. 35
chapter 6 stack 36 6.3 address stack register as shown in figure 6-1, the address stack register consists of five consecutive 10-bit registers. a value equal to the program counter (pc)+1 (return address) is stored during execution of subroutine calls (call addr, call @ar), the first cycle of a table reference (movt dbf, @ar), and upon receipt of an interrupt in the address stack register. the contents of the address register (ar) is also stored when a stack push (push ar) is executed. the address register holding data is pointed to by the address in the stack pointer at execution time less one (address in stack pointer (sp) C 1). when a subroutine return (ret, retsk), an interrupt return (reti), or the second cycle of a table reference (movt dbf, @ar) is executed, the contents of the address pointed to by the stack pointer is restored to the program counter and the stack pointer is incremented. when a stack pop (pop ar) is executed, the value in the address stack register pointed to by the stack pointer is transferred to the address to the address register and the stack pointer is incremented. if more than five subroutine calls or interrupts are executed, an internal reset signal is generated, and the address stack register initializes hardware for start at address 0000h (to prevent a software crash). 6.4 interrupt stack register as shown in figure 6-1, the interrupt stack register consists of one 5-bit register. when an interrupt is received five bits in the system register (sysreg) (mentioned later) that is, each flag (bcd, cmp, cy, z, ixe) of the program status word (psword), are saved. when the interrupt return (reti) is executed, the program status word is restored from the interrupt stack register. in the interrupt stack register, every time an interrupt is received, necessary data is saved. when more than three interrupts are received, the data from the first interrupt is lost. remark all the 5 bits of psword are automatically cleared to zero after being saved in the interrupt stack register. 6.5 stack pointer (sp) and interrupt stack register as shown in figure 6-1, the stack pointer (sp) is a 3-bit binary counter used to point to addresses in the five address stack registers. the stack pointer is located at address 01h in the register file. at reset, the stack pointer is set to 5. as shown in table 6-1, the stack pointer is decremented when subroutine calls (call addr, call @ar), the first cycle of a table reference (movt dbf, @ar), stack push (push ar), and an interrupt are accepted. the stack pointer is incremented at the following times: subroutine returns (ret, retsk), the second instruction cycle of a table reference (movt dbf, @ar), stack pop (pop ar), and an interrupt return (reti). the interrupt stack counter as well as the stack pointer is decremented when an interrupt is accepted. the interrupt stack counter is incremented by an interrupt return (reti) only.
chapter 6 stack 37 table 6-1. operation of the stack pointer instruction stack pointer value counter of interrupt stack register call addr call @ar movt dbf, @ar C1 not changed (1st instruction cycle) push ar interrupt receipt C1 C1 ret retsk movt dbf, @ar +1 not changed (2nd instruction cycle) pop ar reti +1 +1 as mentioned above, the stack pointer is a 3-bit counter and therefore can conceivably store any of the eight values from 0h to 7h. since there are only five address stack registers, however, a stack pointer value that is greater than five will cause an internal reset signal to be generated (to prevent a software crash). since the stack pointer is located in the register file, it can be read and written to directly by using the peek and poke instructions to manipulate the register file. when this is done, the stack pointer value will change but the values in the address stack register will not be affected. 6.6 stack operation during subroutines, table references, and interrupts stack operation during execution of each command is explained in 6.6.1 to 6.6.3 . 6.6.1 stack operation during subroutine calls (call) and returns (ret, retsk) table 6-2 shows operation of the stack pointer (sp), address stack register, and the program counter (pc) during execution of subroutine calls and returns.
chapter 6 stack 38 table 6-2. operation of the stack pointer during execution instruction operation call addr <1> stack pointer (sp) is decremented. <2> program counter (pc) is saved in the address stack register pointed to by the stack pointer (sp). <3> value specified by the instruction operand (addr) is transferred to the program counter. ret <1> value in the address stack register pointed to by the stack pointer (sp) is restored to the program counter (pc). <2> stack pointer (sp) is incremented. when the retsk instruction is executed, the first command after data restoration becomes a no operation instruction (nop). 6.6.2 stack operation during table reference (movt dbf, @ar) table 6-3 shows stack operation during table reference. table 6-3. stack operation during table reference instruction instruction cycle operation movt dbf, @ar first <1> stack pointer (sp) is decremented. <2> program counter (pc) is saved in the address stack register pointed to by the stack pointer (sp). <3> value in the address register (ar) is transferred to the program counter (pc). second <1> contents of the program memory (rom) pointed to by the pro- gram counter (pc) is transferred to the data buffer (dbf). <2> value in the address stack register pointed to by the stack pointer (sp) is restored to the program counter (pc). <3> stack pointer (sp) is incremented. remark as an exception, execution of movt dbf and @ar instructions require two instruction cycle. retsk
chapter 6 stack 39 6.6.3 executing reti instruction table 6-4 shows stack operation during interrupt receipt and reti instruction execution. table 6-4. stack operation during interrupt receipt and return instruction operation receipt of interrupt <1> stack pointer (sp) is decremented. <2> value in the program counter (pc) is saved in the address stack register pointed to by the stack pointer (sp). <3> values in the psword flags (bcd, cmp, cy, z, ixe) are saved in the interrupt stack. <4> vector address is transferred to the program counter (pc) reti <1> values in the interrupt stack register are restored to the psword (bcd, cmp, cy z, ixe). <2> values in the address stack register pointed to by the stack pointer (sp) is restored to the program counter (pc). <3> stack pointer (sp) is incremented. 6.7 stack nesting levels and the push and pop instructions during execution of operations such as subroutine calls and returns, the stack pointer (sp) simply functions as a 3-bit counter which is incremented and decremented. when the value in the stack pointer is 0h and a call or movt instruction is executed or an interrupt is received, the stack pointer is decremented to 7h. the m pd17120 subseries treats this condition as a fault and generates an internal reset signal. in order to avoid this condition, when the address stack register is being used frequently, the push and pop instructions are used as necessary to save/return the address stack register. table 6-5 shows stack operation during the push and pop instructions. table 6-5. stack operation during the push and pop instructions instruction operation push <1> stack pointer (sp) is decremented. <2> value in the address register (ar) is transferred to the address stack register pointed to by the stack pointer (sp). pop <1> value in the address stack register pointed to by the stack pointer (sp) is transferred to the address register (ar). <2> stack pointer (sp) is incremented.
[memo] 40
chapter 7 system register (sysreg) the system register (sysreg), located in data memory, is used for direct control of the cpu. 7.1 system register configuration figure 7-1 shows the allocation address of the system register in data memory. as shown in figure 7-1, the system register is allocated in addresses 74h to 7fh of data memory. because the system register is allocated in data memory, it can be manipulated using any of the instructions available for manipulating data memory. therefore, it is also possible to put the system register in the general register. figure 7-1. allocation of system register in data memory 0 1 2 3 4 5 6 7 0123456789abcdef column address data memory (bank0) 0123 456789abcdef row address port register system register (sysreg) 41
chapter 7 system register (sysreg) 42 figure 7-2 shows the configuration of the system register. as shown in figure 7-2, the system register consists of the following seven registers. ? address register (ar) ? window register (wr) ? bank register (bank) ? index register (ix) ? data memory row address pointer (mp) ? general register pointer (rp) ? program status word (psword) figure 7-2. system register configuration note zeros in the columns indicates "0 fixed". 74h address 77h 75h 76h 78h 79h 7ah 7bh 7ch 7dh 7eh 7fh b 3 b 2 b 1 b 0 ar3 0000 b 3 b 2 b 1 b 0 ar2 0000 b 3 b 2 b 1 b 0 ar1 0000 b 3 b 2 b 1 b 0 ar0 0000 b 3 b 2 b 1 b 0 wr b 3 b 2 b 1 b 0 bank 0000 b 3 b 2 b 1 b 0 ixh mph 0000 b 3 b 2 b 1 b 0 ixm mpl 0000 b 3 b 2 b 1 b 0 ixl 0000 b 3 b 2 b 1 b 0 rph 0000 b 3 b 2 b 1 b 0 rpl 0000 b 3 b 2 b 1 b 0 psw 0000 000000 0000 m p e 0000 0000 b c d c m p c yz i x e name bit symbol data note initial value when reset address register (ar) window register (wr) data memory row address pointer (mp) index register (ix) general register pointer (rp) program status word (psword) not defined (ar) bank register (bank) (bank) (mp) (rp) (ix)
chapter 7 system register (sysreg) 43 7.2 address register (ar) 7.2.1 address register configuration figure 7-3 shows the configuration of the address register. as shown in figure 7-3, the address register consists of the sixteen bits in address 74h to 77h (ar3 to ar0) of the system register. however, because the six high-order bits are always set to 0, the address register is actually 10 bits. when the system is reset, all sixteen bits of the address register are reset to 0. figure 7-3. address register configuration 74h address 77h 75h 76h ar3 ar2 ar1 ar0 name bit symbol data initial value when reset address register (ar) (ar) b 3 b 2 b 1 b 0 000000 0000 b 3 b 2 b 1 b 0 b 3 b 2 b 1 b 0 b 3 b 2 b 1 b 0 7.2.2 address register functions the address register is used to specify an address in program memory when executing an indirect branch instruction (br @ar), indirect subroutine call (call @ar) or table reference (movt dbf, @ar). the address register can also be put on and taken off the stack by using the stack manipulation instructions (push ar, pop ar). items (1) to (4) explain address register operation during execution of each instruction. the address register can be incremented by using the dedicated increment instruction (inc ar). (1) table reference (movt dbf, @ar) when the movt dbf, @ar instruction is executed, the data in program memory (16-bit data) located at the address specified by the value in the address register is read into the data buffer (addresses 0ch to 0fh of bank0).
chapter 7 system register (sysreg) 44 (2) stack manipulation instructions (push ar, pop ar) when the push ar instruction is executed, the stack pointer (sp) is first decremented and then the address register is stored in the address stack pointed to by the stack pointer. when the pop ar instruction is executed, the contents of the address stack pointed to by the stack pointer is transferred to the address register and then the stack pointer is incremented. also refer to chapter 6 . (3) indirect branch instruction (br @ar) when the br @ar instruction is executed, the program branches to the address in program memory specified by the value in the address register. (4) indirect subroutine call (call @ar) when the call @ar instruction is executed, the subroutine located at the address in program memory specified by the value in the address register is called. (5) address register used as peripheral register the address register can be manipulated four bits at a time by using data memory manipulation instructions. the address register can also be used as a peripheral register for transferring 16-bit data to the data buffer. in other words, by using the put ar, dbf and get dbf, ar instructions in addition to the data memory manipulation instructions, the address register can be used to transfer 16-bit data to the data buffer. note that the data buffer is allocated in addresses 0ch to 0fh of bank0 in data memory. figure 7-4. address register used as a peripheral register 0 1 2 3 4 5 6 7 0123456789abcdef column address (bank0) address register row address system register dbf3 dbf2 dbf1 dbf0 ar3 ar2 ar1 ar0 16-bit data transfer available ? ? ? ? ? data buffer
chapter 7 system register (sysreg) 45 7.3 window register (wr) 7.3.1 window register configuration figure 7-5 shows the configuration of the window register. as shown in figure 7-5, the window register (wr) consists of four bits allocated at address 78h of the system register. the contents of the window register is undefined after a system reset. however, when reset input is used to release the system from halt or stop mode, the previous state of the window register is maintained. figure 7-5. window register configuration 7.3.2 window register functions the window register is used to transfer data to and from the register file (rf). data is transferred to and from the register file using the instructions peek wr, rf and poke rf, wr. for details, refer to 9.2.3 register file manipulation instructions . 78h window register wr not defined address name bit symbol data initial value when reset b 3 b 2 b 1 b 0
chapter 7 system register (sysreg) 46 7.4 bank register (bank) figure 7-6 shows the configuration of the bank register. the bank register consists of four bits at address 79h (bank) of the system register. bank register is a register for switching the banks of ram. however, since the m pd17120 subseries has only one bank, every bank register bit is fixed to 0. figure 7-6. bank register configuration 79h bank register address name bit symbol data initial value when reset b 3 b 2 b 1 b 0 0000 0 (bank) bank
chapter 7 system register (sysreg) 47 7.5 index register (ix) and data memory row address pointer (memory pointer: mp) 7.5.1 index register (ix) ix is used for address modification to data memory. it differs from mp in that its modification object is an address that is specified as the bank or operand m. as shown in figure 7-7, ix is mapped to a total of 12 bits of system registers: 7ah (ixh), 7bh (ixm), and 7ch (ixl). the index register enable flag (ixe) which enables address modification by ix is allocated to the lowest bit of the psw. when ixe=1, an address in data memory specified with operand m is not m but the address indicated by the or of m, ixm and ixl. the bank specified at this time is that indicated by the or of bank and ixh. remark the ixh of the m pd17120 subseries is "fixed to 0" and therefore the bank is modified even when ixe=1 (thus preventing the bank from becoming other than 0). 7.5.2 data memory row address pointer (memory pointer: mp) mp is used for address modification to data memory. it differs from ix in that its modification object is the row address of the address that is indirectly specified with the bank and operand @r. as shown in figure 7-7, mph and ixh, and mpl and ixm, are respectively mapped to the same addresses (system registers 7ah and 7bh). it is mph's lower 3 bits and mpl's full 7 bits that are actually functioning as the mp. to mph's most significant bit is allocated the memory pointer enable flag (mpe) which enables address modification by the mp. when mpe=1, the bank and row address of the data memory indirectly specified with operand @r is not bank and m r but the address specified by the mp. (the column address is specified with the contents of r regardless of the mpe.) at this time, mph's lower 3 bits and mpl's most significant 4 bits point to bank; and mpl's lower 3 bits point to the row address. remark the mph's lower 3 bits and mpl's most significant bit in the m pd17120 subseries are "fixed to 0" and therefore the bank is cleared to 0 even when mpe=1 (thus preventing the bank from becoming other than 0).
chapter 7 system register (sysreg) 48 figure 7-7. index register and memory pointer configuration figure 7-8. data memory address modification by index register and memory pointer bank : bank register mp : memory pointer ix : index register mpe : memory pointer enable flag ixe : index enable flag mph : memory pointer's upper 3 bits ixh : index register's bits 10-8 mpl : memory pointer's lower 4 bits ixm : index register's bits 7-4 r : general register column address ixl : index register's bits 3-0 rp : general register pointer m : data memory address indicated by m r , m c ( ) : contents addressed with m r : data memory row address : direct address such as r m c : data memory column address 7ah address name bit symbol name data reset-time value b 3 b 2 b 1 b 0 b 3 b 2 b 1 b 2 b 1 b 1 b 0 b 0 index register (ix) memory pointer (mp) ixh mph ixm mpl ixl 0000 00000000000 (ix) (mp) flag name m p e 7bh 7ch b 1 b 2 b 3 0 0 0 0 7fh psw i x e 0 program status word (psword)'s lower 4 bits b 3 data memory address specified with m ixe 0 0 1 1 b 3 b 2 b 1 b 0 bank bank bank ixh b 3 b 2 b 1 b 0 b 3 b 2 b 1 b 0 b 3 b 2 b 1 b 0 b 2 b 1 b 0 b 2 b 1 b 0 row address column address bank row address column address indirect transfer address specified with @m m bank m r (r) mph mpl (r) bank m r (r) ixm ixl ixh ixm mpe 0 1 0 1 m setting disabled logical or logical or same as above
chapter 7 system register (sysreg) 49 table 7-1. address-modified instruction statements add addc sub subc and or r, m xor m, #n4 skt skf ske skge sklt skne ld r, m st m, r mov m, #n4 @r, m m, @r r, m m, #n4 m, #n m, #n4 arithmetic operation logical operation judge- ment comparison transfer ------------------------------------------------------------ ------------------------------------------------------------ ------------------------------------------------------------
chapter 7 system register (sysreg) 50 7.5.3 mpe=0 and ixe=0 (no data memory modification) as shown in figure 7-8, data memory addresses are not affected by the index register and the data memory row address pointer. (1) data memory manipulation instructions example 1. general register is in row address 0 r003 mem 0.03h m061 mem 0.61h add r003, m061 as shown in figure 7-9, when the above instructions are executed, the data in general register address r003 and data memory address m061 are added together and the result is stored in general address r003. (2) indirect transfer of data in the general register (horizontal indirect transfer) example 2. general register is in row address 0 r005 mem 0.05h m034 mem 0.34h mov r005, #8 ; r005 ? 8 mov @r005, m034 ; indirect transfer of data in the register as shown in figure 7-9, when the above instructions are executed, the data stored in data memory address m034 is transferred to data memory location 38h. in other words, the mov @r, m instruction causes the contents in the data memory address specified by m to be transferred to the data memory location specified by @r (which by definition has the same row address as m). the indirect data transfer address has the same row address as m (example above uses row address 3) and the column address is the value contained in the general register address specified by r (example above uses column address 8). therefore the address in the above example is 38h.
chapter 7 system register (sysreg) 51 example 3. general register is in row address 0 r00b mem 0.0bh m034 mem 0.34h mov r00b, #0eh ; r00b ? 0eh mov m034, @r00b ; indirect transfer of data in the register as shown in figure 7-9, when the above instructions are executed, the contents of data memory stored at address 3eh is transferred to data memory location m034. in other words, the mov m, @r instruction causes the contents of the data memory location specified by @r (which by definition has the same row address as m) to be transferred to the data memory location specified by m. the indirect data transfer address has the same row address as m (example above uses row address is 3) and the column address is the value contained in the general register address specified by r (example above uses column address 0eh). therefore the address in the above example is 3eh. the data transfer memory address source and destination in this example are the opposite of those shown in example 2 (source and destination are switched). figure 7-9. example of operation when mpe=0 and ixe=0 0 1 2 3 4 5 6 7 0123456789abcdef system register general register 8 e row address example 2. mov @r005, m034 example 1. add r003, m061 column address specified as transfer destination column address specified as transfer source example 3. mov m034, @r00b column address data memory address m general register address r 0000 0000 110 000 0001 0011 column address row address bank addresses in example 1 add r003, m061 data memory address m general register address r indirect transfer address @r 0000 0000 0000 011 000 011 0100 0101 1000 column address row address bank same as m contents of r addresses in example 2 mov @r005, m034
chapter 7 system register (sysreg) 52 7.5.4 mpe=1 and ixe=0 (diagonal indirect data transfer) as shown in figure 7-8, the indirect data transfer bank and row address specified by @r become the data memory row address pointer value only when general register indirect data transfer instructions (mov @r, m and mov m, @r) are used. example 1. when the general register is in row address 0 r005 mem 0.05h m034 mem 0.34h mov mpl, #0110b ; mp ? 6 mov r005, #8 ; r005 ? 8 mov mph, #1000b ; mpe ? 1 mov @r005, m034 ; indirect transfer of data in the register as shown in figure 7-10, when the above instructions are executed, the contents of data memory address m034 is transferred to data memory location 68h. when the mov @r, m instruction is executed when mpe=1, the contents of the data memory address specified by m is transferred to the column address pointed to by the row address @r being pointed to by the memory pointer. in this case, the indirect address specified by @r becomes the value used for the bank and row address data memory pointer (above example uses row address 6). the column address is the value in the general register address specified by r (above example uses column address 8). therefore the address in the above example is 68h. this example is different from example 2 in 7.5.3 when mpe=0 for the following reasons: in this example, the data memory row address pointer is used to point to the indirect address bank and row address specified by @r. (in example 2 in 7.5.3 the indirect address bank and row address are the same as m.) by setting mpe=1, diagonal indirect data transfer can be performed using the general register.
chapter 7 system register (sysreg) 53 example 2. general register is in row address 0 r00b mem 0.0bh m034 mem 0.34h mov mpl, #0110b ; mp ? 6 mov mph, #1000b ; mpe ? 1 mov r00b, #0eh ; r00b ? 0eh mov m034, @r00b ; indirect transfer of data in the register as shown in figure 7-10, when the above instructions are executed, the data stored in address 6eh is transferred to data memory location m034. figure 7-10. example of operation when mpe=1 and ixe=0 0 1 2 3 4 5 6 7 0 system register row address example 1. mov @r005, m034 column address specified as transfer destination column address specified as transfer source column address 123456789abcdef 8e general register memory pointer =00110b example 2. mov m034, @r00b data memory address m general register address r indirect transfer address @r 0000 0000 0000 011 000 110 0100 0101 1000 column address row address bank contents of r addresses in example 1 mov @r005, m034 data memory address m general register address r indirect transfer address @r 0000 0000 0000 011 000 110 0100 1011 1110 column address row address bank contents of r addresses in example 2 mov, m034 @r00b contents of mp contents of mp
chapter 7 system register (sysreg) 54 7.5.5 mpe=0 and ixe=1 (index modification) as shown in figure 7-8, when a data memory manipulation instruction is executed, any bank or address in data memory specified by m can be modified using the index register. when indirect data transfer using the general register (mov @r, m or mov m, @r) is executed, the indirect transfer bank and address specified by @r can be modified using the index register. address modification is done by performing an or operation on the data memory address and the index register. the data memory manipulation instruction being executed manipulates data in the memory location pointed to by the result of the operation (called the real address). examples are shown below. example 1. when the general register is in row address 0 r003 mem 0.03h m061 mem 0.61h mov ixl, #0010b ; ix ? 00000010010b mov ixm, #0001b ; mov ixh, #0000b ; mpe ? 0 or psw, #.df.ixe and 0fh ; ixe ? 1 add r003, m061 as shown in figure 7-11, when the instructions of example 1 are executed, the value in data memory address 73h (real address) and the value in general register address r003 (address location 03h) are added together and the result is stored in general register address r003. when the add r, m instruction is executed, the data memory address specified by m (address 61h in above example) is index modified. modification is done by performing an or operation on data memory location m061 (address 61h, binary 00001100001b) and the index register (00000010010b in the above example). the result of the operation (00001110011b) is used as a real address (address location 73h) by the instruction being executed. as compared to when ixe=0 (examples in 7.5.3 ), in this example the data memory address being directly specified by m is modified by performing an or operation on m and the index register.
chapter 7 system register (sysreg) 55 figure 7-11. example of operation when mpe=0 and ixe=1 0 1 2 3 4 5 6 7 0 system register row address example 1. add @r003, m061 index modification column address 123456789abcdef r003 general register data memory address m general register address r index modification 0000 0000 0000 bank 0000 ixh 0000 110 000 110 001 ixm 111 0001 0011 0001 0010 ixl 0011 column address row address bank addresses in example 1 add r003, m061 m061 : 00001100001b ix : 00000010010b or) real address 00001110011b m061 m061 ix real address (or operation) m instruction is executed using this address.
chapter 7 system register (sysreg) 56 example 2. indirect data transfer using the general register assume that the general register is row address 0. r005 mem 0.05h m034 mem 0.34h mov ixl, #0001b ; ix ? 00000000001b mov ixm, #0000b ; mov ixh, #0000b ; mpe ? 0 or psw, #.df.ixe and 0fh ; ixe ? 1 mov r005, #8 ; r005 ? 8 mov @r005, m034 ; indirect data transfer using the register as shown in figure 7-12, when the above instructions are executed, the contents of data memory address 35h is transferred to data memory location 38h. when the mov @r, m instruction is executed when ixe=1, the data memory address specified by m (direct address) is modified using the contents of the index register. the bank and row address of the indirect address specified by @r are also modified using the index register. the bank, row address, and column address specified by m (direct address) are all modified, and the bank and row address specified by @r (indirect address) are modified. therefore, in the above example the direct address is 35h and the indirect address is 38h. this example is different from example 3 in 7.5.3 when ixe=0 for the following reasons: in this example, the bank, row address and column address of the direct address specified by m are modified using the index register. the general register is transferred to the address specified by the column address of the modified data memory address and the same row address. (in example 3 in 7.5.3 the direct address is not modified.)
chapter 7 system register (sysreg) 57 figure 7-12. example of operation when mpe=0 and ixe=1 0 1 2 3 4 5 6 7 0 system register row address example 2. mov @r005, m034 index modification column address 123456789abcdef general register m034 : 00000110100b ix : 00000000001b or) real address 00000110101b m034 8 indirect address column address specified as transfer destination direct address r005 example 3. clearing all data memory (setting to 0) m000 mem 0.00h mov ixl, #0 ; ix ? 0 mov ixm, #0 ; mov ixh, #0 ; mpe ? 0 loop: or psw, #.df.ixe and 0fh ; ixe ? 1 mov m000, #0 ; set data memory specified by ix to 0 inc ix ; ix ? ix+1 and psw, #1110b ; ixe ? 0: ixe is set to 0 so that ; address 7fh is not modified by ix. ske ixm, #0111b ; row address 7? br loop ; if not 7 then loop (row address is ; not cleared)
chapter 7 system register (sysreg) 58 example 4. processing an array as shown in figure 7-13, to perform the operation: a(n) = a(n) + 4 (0 n 15) on the element a(n) of a one-dimensional array in which an element is 8 bits, the following instructions are executed: m000 mem 0.00h m001 mem 0.01h mov ixh, #0 mov ixm, #n shr 3 ; set the offset of the row address. mov ixl, #n shl 1 and 0fh ; set the offset of the column address. or psw, #.df.ixe and 0fh ; ixe ? 1 add m000, #4 ; addc m001, #0 ; a(n) ? a(n) + 4 in the example above, because an element is 8 bits, the value resulting from left-shifting the n's value by 1 bit is set for the index register. figure 7-13. example of operation when mpe=0 and ixe=1 (array processing) 0 1 2 3 4 5 6 7 0 system register row address column address a (0) 123456789abcdef a (0) a (8) a (1) a (9) a (2) a (10) a (3) a (11) a (4) a (12) a (5) a (13) a (6) a (14) a (7) a (15) 00h 01h b 3 b 2 b 1 b 0 b 7 b 6 b 5 b 4
chapter 7 system register (sysreg) 59 7.6 general register pointer (rp) 7.6.1 general register pointer configuration figure 7-14 shows the configuration of the general register pointer. figure 7-14. general register pointer configuration as shows in figure 7-14, the general register pointer consists of seven bits; four bits in system register address 7dh (rph) and the three high-order bits of system register address 7eh (rpl). however, because the four bits of address 7dh are always set to 0, the register effectively consists of the three high-order bits of address 7eh. all register bits are cleared to 0 at reset. 7dh address name bit symbol data initial value when reset b 3 b 2 b 1 b 0 0000 0 (rp) rph 7eh general register pointer (rp) b 3 b 2 b 1 b 0 b c d 0 rpl flag
chapter 7 system register (sysreg) 60 7.6.2 functions of the general register pointer the general register pointer is used to specify the location of the general register in data memory. for a more detailed explanation, refer to chapter 8 general register (gr) . the general register consists of sixteen nibbles in any single row of data memory. as shown in figure 7-15, the general register pointer is used to indicate which row address is being used as the general register. since the general register pointer effectively consists of three bits, the data memory row addresses in which the general register can be placed are address locations 0h to 7h of bank0. in other words, any row in data memory can be specified as the general register. with the general register allocated in data memory, data can be transferred to and from, and arithmetic/logical operations can be performed on the general register and data memory. note that addresses 40h to 6eh are uninstalled memory locations and should therefore not be specified as locations for the general register. for example, when instructions such as add r,m and ld r,m are executed, instruction operand r can specify an address in the general register and m specifies an address in data memory. in this way, operations like addition and data transfer can be performed on and between data memory and the general register. figure 7-15. general register configuration notes 1. these bits should not be specified in the case of the m pd17120 and 17121. 2. this bit is allocated to bcd flag. b 1 0 1 0 1 0 1 0 1 b 2 0 0 1 1 0 0 1 1 b 3 0 0 0 0 1 1 1 1 b 0 b 1 b 2 b 3 b 0 fixed to 0 fixed to 0 fixed to 0 fixed to 0 note 2 rph rpl ? y ? t note 1 0 1 2 3 4 5 6 7 0123456789abcdef bp general register (16 nibbles) system register bank0 general register pointer (rp) example : general register with rph=0000b rpl=010 b area in which general register can be specified column address
chapter 7 system register (sysreg) 61 7.7 program status word (psword) 7.7.1 program status word configuration figure 7-16 shows the configuration of the program status word. figure 7-16. program status word configuration 7eh address name bit symbol initial value when reset b 3 b 2 b 1 b 0 0 rpl 7fh program status word (psword) b 3 b 2 b 1 b 0 i x e 0 psw data z c y c m p b c d (rp) as shown in figure 7-16, the program status word consists of five bits; the least significant bit of system register address 7eh (rpl) and all four bits of system register address 7fh (psw). the program status word is divided into the following 1-bit flags: binary coded decimal flag (bcd), compare flag (cmp), carry flag (cy), zero flag (z), and the index enable flag (ixe). all register bits are cleared to 0 at reset and at saved at interrupt stack register.
chapter 7 system register (sysreg) 62 7.7.2 functions of the program status word the flags of the program status word are used for setting conditions for arithmetic/logical operations and data transfer instructions and for reflecting the status of operation results. figure 7-17 shows an outline of the functions of the program status word. figure 7-17. outline of functions of the program status word 7fh b 0 7eh psw rpl address symbol flag b 1 b 2 b 3 b 0 b 1 b 2 b 3 i x e z c y c m p b c d used to specify that index modification be performed on the data memory address used when a data memory manipulation instruction is executed. 0: index modification disabled. 1: index modification enabled. set when the result of an arithmetic operation is 0. 0: indicates that the result of the arithmetic operation is a value other than 0. 1: indicates that the result of the arithmetic operation is 0. set when there is a carry in the result of an addition operation or a borrow in the result of a subtraction operation. 0: indicates there was no carry or borrow. 1: indicates there was a carry or borrow. used to specify that the result of an arithmetic operation not be stored in data memory or the general register but just be reflected in the cy and z flags. 0: results of arithmetic operations are stored. 1: results of arithmetic operations are not stored. used to specify how arithmetic operations are performed. 0: arithmetic operations are performed in 4-bit binary. 1: arithmetic operations are performed in bcd. flag function of psword ixe z cy cmp bcd bit
chapter 7 system register (sysreg) 63 7.7.3 index enable flag (ixe) the ixe flag is used to enable to modify index of the data memory address, whether index modification is to be performed on the data memory address used. for a more detailed explanation, refer to 7.5 index register (ix) and data memory row address pointer (memory pointer: mp) . 7.7.4 zero flag (z) and compare flag (cmp) the z flag indicates whether the result of an arithmetic operation is 0. the cmp flag is used to specify that the result of an arithmetic operation not be stored in data memory or the general register. table 7-2 shows how the cmp flag affects the setting and resetting of the z flag. table 7-2. zero flag (z) and compare flag (cmp) condition when cmp=0 when cmp=1 when the result of the arithmatical operation is 0 z ? 1 z remains unchanged when the result of the arithmetic operation is other than 0 z ? 0z ? 0 the z and cmp flags are used to compare the contents of the general register with those of the data memory. the z flag does not change other than in arithmetic operations; the cmp flag does not change other than in bit decisions. example of 12-bit data comparision ; is the 12-bit data stored in m001, m002, and m003 equivalent to 456h? cmp456: set2 cmp, z sub m001, #4 ; data stored in m001, m002, and m003 are not sub m002, #5 ; damaged sub m003, #6 ; ; clr1 cmp skt z ; cmp is automatically cleared by the bit decision instruction br differ ; 1 456h br agree ; =456h
chapter 7 system register (sysreg) 64 7.7.5 carry flag (cy) the cy flag shows whether there is a carry in the result of an addition operation or a borrow in the result of a subtraction operation. the cy flag is set (cy=1) when there is a carry or borrow in the result and reset (cy=0) when there is no carry or borrow in the result. when the rorc r instruction (contents in the general register pointed to by r is shifted right one bit) is executed, the following occurs: the value in the cy flag just before execution of the instruction is shifted to the most significant bit of the general register and the least significant bit is shifted to the cy flag. the cy flag is also useful for when the user wants to skip the next instruction when there is a carry or borrow in the result of an operation. the cy flag is only affected by arithmetic operations and rotations. also, it is not affected by cmp flag. 7.7.6 binary-coded decimal flag (bcd) the bcd flag is used to specify bcd operations. when the bcd flag is set (bcd=1), all arithmetic operations will be performed in bcd. when the bcd flag is reset (bcd=0), arithmetic operations are performed in 4-bit binary. the bcd flag does not affect logical operations, bit evaluation, comparison evaluations or rotations. 7.7.7 caution on use of arithmetic operations on the program status word when performing arithmetic operations (addition and subtraction) on the program status word (psword), the following point should be kept in mind. when an arithmetic operation is performed on the program status word and the result is stored in the program status word. below is an example. example mov psw, #0001b add psw, #1111b when the above instructions are executed, a carry is generated which should cause bit 2 (cy flag) of psw to be set. however, the result of the operation (0000b) is stored in psw, meaning that cy does not get set.
chapter 7 system register (sysreg) 65 7.8 cautions on use of the system register 7.8.1 reserved words for use with the system register because the system register is allocated in data memory, it can be used in any of the data memory manipulation instructions. as shown in example 1 (using a 17k series assembler - as17k), because a data memory address can not be directly specified in an instruction operand, it needs to be defined as a symbol beforehand. the system register is data memory, but has specialized functions which make it different from general-purpose data memory. because of this, the system register is used by defining it beforehand with symbols (used as reserved words) in the assembler (as17k). reserved words for use with the system register are allocated in address locations 74h to 7fh. they are defined by the symbols (ar3, ar2, ..., psw) shown in figure 7-2. as shown in example 2 , if these reserved words are used, it is not necessary to define symbols. for information concerning reserved words, refer to chapter 19 assembler reserved words . example 1. mov 34h, #0101b ; using a data memory address like 34h or 76h will mov 76h, #1010b ; cause an error in the assembler. m037 mem 0.37h ; addresses in general data memory need to be mov m037, #0101b ; defined as symbols using the mem pseudo instruction. 2. mov ar1, #1010b ; by using the reserved word ar1 (address 76h), ; there is no need to define the address as a symbol. ; reserved word ar1 is defined in a device file with ; the pseudo instruction "ar1 mem 0.76h". assembler as17k has the below flag symbol handling instructions defined as macros. setn: set a flag to 1 clrn: rest a flag to 0 sktn: skip when all flags are 1 skfn: skip when all flags are 0 notn: invert a flag initflg: initialize a flag
chapter 7 system register (sysreg) 66 by using these macro instructions, data memory can be handled as flags as shown below in example 3 . the functions of the program status word and the memory pointer enable flag are defined in bit units (flag units) and each bit has a reserved word mpe, bcd, cmp, cy, z and ixe defined for it. if these flag reserved words are used, the incorporated macro instructions can be used as shown in example 4 . example 3. f0003 flg 0.00.3 ; flag symbol definition set1 f0003 ; incorporated macro expanded macro or .mf.f0003 shr 4, #.df.f0003 and 0fh ; set bit 3 of address 00h of bank0 example 4. set1 bcd ; incorporated macro expanded macro or .mf.bcd shr 4, #.df.bcd and 0fh ; set the bcd flag ; bcd is defined as "bcd flg 0.7eh.0" clr2 z, cy ; identical address flag expanded macro and .mf.z shr 4, #.df. (not (z or cy) and 0fh) clr2 z, bcd ; different address flag expanded macro and .mf.z shr 4, #.df. (not z and 0fh) and .mf.bcd shr 4, #.df. (not bcd and 0fh)
chapter 7 system register (sysreg) 67 7.8.2 handling of system register addresses fixed at 0 in dealing with system register addresses fixed at 0 (refer to figure 7-2 ), there are a few points for which caution should be taken with regard to device, emulator and assembler operation. items (1), (2) and (3) explain these points. (1) concerning device operation trying to write data to an address fixed at 0 will not change the value (0) at that address. any attempt to read an address fixed at 0 will result in the value 0 being read. (2) when using a 17k series in-circuit emulator (ie-17k or ie-17k-et) an error will be generated if a write instruction attempts to write the value 1 to an address fixed at 0. below is an example of the type of instructions that will cause the in-circuit emulator to generate an error. example 1. mov bamk, #0100b ; attempts to write the value 1 to bit 3 (an address fixed at 0). 2. mov ixl, #1111b ; mov ixm, #1111b ; mov ixh, #0001b ; add ixl, #1 ; addc ixm, #0 ; addc ixh, #0 ; however, when all valid bits are set to 1 as shown in example 2 , executing the instructions inc ar or inc ix will not cause an error to be generated by the in-circuit emulator. this is because when all valid bits of the address register and index register are set to 1, executing the inc instruction causes all bits to be set to 0. the only time the in-circuit emulator will not generate an error when an attempt is made to write the value 1 to a bit fixed at 0 is when the address being written to is in the address register.
chapter 7 system register (sysreg) 68 (3) when using a 17k series assembler (as17k) no error is output when an attempt is made to write the value 1 to a bit fixed at 0. the instruction shown in example 1 mov bank, #0100b will not cause an assembler error. however, when the instruction is executed in the in-circuit emulator, an error is generated. the assembler (as17k) does not generate errors because it does not check the correspondence between the symbol (including reserved words) and the data memory address which are the objects of the data memory operation instruction. however, in the following case, the assembler generates an error: when a value of 1 or more is given to "n" in the incorporation macro instruction "bankn". this is so because the assembler determine that no incorporation macro instructions other than bank0 can be used on the m pd17120 subseries.
chapter 8 general register (gr) the general register (gr) is allocated in data memory. it can therefore be used directly in performing arithmetic/ logical operations with and in transferring data to and from general data memory. 8.1 general register configuration figure 8-1 shows the configuration of the general register. as shown in figure 8-1, sixteen nibbles in a single row address in data memory (16 4 bits) are used as the general register. the general register pointer (rp) in the system register is used to indicate which row address is to be used as the general register. because the rp effectively has three valid bits, the data memory row addresses in which the general register can be allocated are address locations 0h to 7h. however, note that addresses 40h to 6eh are uninstalled memory locations and should therefore not be specified as locations for the general register. 8.2 functions of the general register the general register can be used in transferring data to and from data memory within an instruction. it can also be used in performing arithmetic/logical operations with data memory within an instruction. in effect, since the general register is data memory, this just means that operations such as arithmetic/logical operations and data transfer can be performed on and between locations in data memory. in addition, because the general register is allocated in data memory, it can be controlled in the same manner as other areas in data memory through the use of data memory manipulation instructions. 69
chapter 8 general register (gr) 70 figure 8-1. general register configuration 0 1 2 3 4 5 6 7 0123456789abcdef rp general register (16 nibbles) system register bank0 general register when rph=0000b rpl=010 b 7dh address name bits symbol data b 3 b 2 b 1 b 0 0 b 3 b 2 b 1 b 0 7eh b c d rph rpl general register pointer (rp) 000000 reset 0000 row address the general register pointer (rp) can be used to specify any row address in address locations 0h to 7h column address
chapter 9 register file (rf) the register file is a register used mainly for specifying conditions for peripheral hardware. 9.1 register file configuration 9.1.1 configuration of the register file figure 9-1 shows the configuration of the register file. as shown in figure 9-1, the register file is a register consisting of 128 nibbles (128 words 4 bits). in the same way as with data memory, the register file is divided into address in units of four bits. it has a total of 128 nibbles specified in row addresses from 0h to 7h and column address from 0h to 0fh. address locations 00h to 3fh define an area the control register. figure 9-1. register file configuration 0 1 2 3 4 5 6 7 general register 0 row address column address 123456789abcdef 9.1.2 relationship between the register file and data memory figure 9-2 shows the relationship between the register file and data memory. as shown in figure 9-2, the register file overlaps with data memory in addresses 40h to 7fh. this means that the same memory exists in register file addresses 40h to 7fh and in data memory bank addresses 40h to 7fh. 71
chapter 9 register file (rf) 72 figure 9-2. relationship between the register file and data memory 0 1 2 3 4 5 6 7 data memory 0 row address column address 123456789abcdef bank0 system register control register port register 0 1 2 3 re g ister file 9.2 functions of the register file 9.2.1 functions of the register file the register file is mainly used as a control register (a register called the control register is allocated in the register file) for specifying conditions for peripheral hardware. this control register is allocated within the register file at address location 00h to 3fh. the rest of the register file (40h to 7fh) overlaps with data memory. as shown in 9.2.3 , because of this overlap, this area of the register file is the same as normal memory with one exception: the register file manipulation instructions peek and poke can be used with this area of memory but not with normal data memory. 9.2.2 control register functions the peripheral hardware whose conditions can be controlled by control registers is listed below. for details concerning peripheral hardware and the control register, refer to the section for the peripheral hardware concerned. ? stack ? int pin ? power-on/power-down reset ? comparator ? timer ? general ports ? serial interface ? interrupts
chapter 9 register file (rf) 73 9.2.3 register file manipulation instructions reading and writing data to and from the register file is done using the window register (wr: address 78h) located in the system register. reading and writing of data is performed using the following dedicated instructions: peek wr, rf: read the data in the address specified by rf and put it into wr. poke rf, wr: write the data in wr into the address specified by rf. below is an example using the peek and poke instructions. example m030 mem 0.30h ; address 30h of the data memory is used as save area of wr. m032 mem 0.32h ; address 32h of the data memory is used as operation area of wr. rf11 mem 0.91h ; symbol definition rf33 mem 0.b3h ; register file addresses 00h to 3fh must be defined with rf70 mem 0.70h ; symbols as bank0 address 80h to bfh. rf73 mem 0.73h ; refer to 9.4 notes on using the register file for details. ; bank0 <1> peek wr, rf11 ; clr1 mpe ; shows the example of saving wr contents to the general data clr1 ixe ; memory (addresses 00h to 3fh). for example, it shows the or rpl, #0110b ; case of saving wr contents to address 30h of the data memory <2> ld m030, wr ; without address modification. <3> poke rf73, wr ; data memory of addresses 40h to 7fh and control register can <4> peek wr, rf70 ; transmit/receive data to/from wr directly by peek and poke <5> poke rf33, wr ; instruction. <6> st wr, m032 ;
chapter 9 register file (rf) 74 figure 9-3 shows an example of register file operation. as shown in figure 9-3, reading and writing of data to and from the control register (address locations 00h to 3fh) is performed using the "peek wr, rf" and "poke rf, wr" instructions. data within the control register specified using rf can be read from and written to the control register, only by using these instructions with the window register. the fact that the register file overlaps with data memory in addresses 40h to 7fh has the following effect: when a "peek wr, rf" or "poke rf, wr" instruction is executed, the effect is the same as if they were being executed on the data memory address (in the current bank) specified by rf. addresses 40h to 7fh of the register file can be operated by normal memory manipulation instructions. control registers can be manipulated in 1-bit unit by using built-in macro instruction. figure 9-3. accessing the register file using the peek and poke instructions 0 1 2 3 4 5 6 7 0 system register <6> st column address 123456789abcdef data memory <2> ld m030, wr <3> poke rf73, wr <4> peek wr, rf70 bank0 0 1 2 3 row address <1> peek wr, rf11 <5> poke rf33, wr control register wr, m032 wr register file
chapter 9 register file (rf) 75 9.3 control register the control register consists of 64 nibbles (64 4 bits) allocated in register file address locations 00h to 3fh. of these nibbles, only 17 nibbles are actually used in the m pd17120 and 17121, and 20 nibbles are used in the m pd17132, 17133, 17p132, and 17p133. there are two types of registers, both of which occupy one nibble of memory. one type is read/write (r/w), and the other is read-only (r). note that within the read/write (r/w) flags, there exists a flag that will always be read as 0. the following read/write (r/w) flags are those flags which will always be read as 0: ? tmres (rf: 11h, bit 2) within the four bits of data in a nibble, there are bits which are fixed at 0 and will therefore always be read as 0. these bits remain fixed at 0 even when an attempt is made to write to them. attempting to read data in the unused register address area will yield unpredictable values. in addition, attempting to write to this area has no effect. concerning the configuration of control register, refer to figures 19-1 and 19-2 . 9.4 cautions on using the register file 9.4.1 concerning operation of the control register (read-only and unused registers) it is necessary to take note of the following notes concerning device operation and use of the 17k series assembler (as17k) and in-circuit emulator (ie-17k or ie-17k-et) with regard to the read-only (r) and unused registers in the control register (register file address locations 00h to 3fh). (1) device operation writing to a read-only register has no effect. attempting to read data from an address in the unused data area will yield an unpredictable value. attempting to write to an address in the unused data area has no effect. (2) during use of the assembler (as17k) an error will be generated if an attempt is made to write to a read-only register. an error will also be generated if an attempt is made to read from or write to an address in the unused data area.
chapter 9 register file (rf) 76 (3) during use of the in-circuit emulator (ie-17k or ie-17k-et) (operation during patch processing and similar operations) attempting to write to a read-only register has no effect and no error is generated. attempting to read data from an address in the unused data area will yield an unpredictable value. attempting to write to an address in the unused data area has no effect and no error is generated. 9.4.2 register file symbol definitions and reserved words attempting to use a numerical value in a 17k series assembler (as17k) to specify a register file address in the rf operand of the peek wr, rf or poke rf, wr instructions will cause an error to be generated. therefore, as shown in example 1 , register file addresses need to be defined beforehand as symbols. example 1. case which causes and error to be generated peek wr, 02h ; poke 21h, wr ; case in which no error is generated rf71 mem 0.71h ; symbol definition peek wr, rf71 ; caution should especially be taken with regard to the following point: ? when using a symbol to define the control register as an address in data memory, it needs to be defined as addresses 80h to bfh of bank0. since the control register is manipulated using the window register, any attempt to manipulate the control register other than by using the peek and poke commands needs to cause an error to be generated in the assembler (as17k). however, note that any address in the area of the register file overlapping with data memory (address locations 40h to 7fh) can be defined as a symbol in the same manner as with normal data memory. an example is given below. example 2. rf71 mem 0.71h ; address in register file overlapping with data memory rf02 mem 0.82h ; control register peek wr, rf71 ; rf71 becomes address 71h peek wr, rf02 ; rf02 becomes address 02h in the control register.
chapter 9 register file (rf) 77 the assembler (as17k) has the below flag symbol handling instructions defined internally as macros. setn: set a flag to 1 clrn: reset a flag to 0 sktn: skip when all flags are 1 skfn: skip when all flags are 0 notn: invert a flag initflg: initialize a flag (data setting per 4 bits) by using these incorporated macro instructions, the contents of the register file can be manipulated one bit at a time. due to the fact that most of control register consists of 1-bit flags, the assembler (as17k) has reserved words (predefined symbols) for use with these flags. however, note that there is no reserved word for the stack pointer for its use as a flag. the reserved word used for the stack pointer is "sp", for its use as data memory. for this reason, none of the above flag manipulation instructions using reserved words can be used for the stack pointer.
[memo] 78
chapter 10 data buffer (dbf) the data buffer consists of four nibbles allocated in addresses 0ch to 0fh in bank0. the data buffer is used as a data storage area when data is transferred to/from the cpu peripheral circuit (address register, serial interface, and timer) by the get and put instructions. by using the movt dbf, and @ar instructions, fixed data in program memory can be read into the data buffer. 10.1 data buffer configuration figure 10-1 shows the allocation of the data buffer in data memory. as shown in figure 10-1, the data buffer is allocated in address locations 0ch to 0fh in bank0 and consists of a total of 16 bits (4 4 bits). figure 10-1. allocation of the data buffer 0 1 2 3 4 5 6 7 0 bank0 column address 123456789abcdef data memory data buffer (dbf) system register (sysreg) row address figure 10-2 shows the configuration of the data buffer. as shown in figure 10-2, the data buffer is made up of sixteen bits with its least significant bit in bit 0 of address 0fh and its most significant bit in bit 3 of address 0ch. 79
chapter 10 data buffer (dbf) 80 figure 10-2. data buffer configuration address bit data b 3 b 2 b 1 b 0 dbf3 symbol bit b 15 b 14 b 13 b 12 b 3 b 2 b 1 b 0 dbf2 b 11 b 10 b 9 b 8 b 3 b 2 b 1 b 0 dbf1 b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0 dbf0 b 3 b 2 b 1 b 0 0ch 0dh 0eh 0fh m s b < > < > l s b data memory bank0 data buffer data because the data buffer is allocated in data memory, it can be used in any of the data memory manipulation instructions. 10.2 functions of the data buffer the data buffer has two separate functions. the data buffer is used for data transfer with peripheral hardware. the data buffer is also used for reading constant data in program memory. figure 10-3 shows the relationship between the data buffer and peripheral hardware. figure 10-3. relationship between the data buffer and peripheral hardware 01h shift register (siosfr) peripheral hardware 02h 03h timer modulo register (tmm) 40h address register (ar) data buffer (dbf) constant data program memory (rom) internal bus peripheral address timer count register (tmc)
chapter 10 data buffer (dbf) 81 10.2.1 data buffer and peripheral hardware table 10-1 shows data transfer with peripheral hardware using the data buffer. each unit of peripheral hardware has an individual address (called its peripheral address). by using this peripheral address and the dedicated instructions get and put, data can be transferred between each unit of peripheral hardware and the data buffer. get dbf, p : read the data in the peripheral hardware address specified by p into the data buffer (dbf). put p, dbf: write the data in the data buffer to the peripheral hardware address specified by p. there are three types of peripheral hardware units: read/write (put/get), write-only (put) and read-only (get). the following describes what happens when a get instruction is used with write-only hardware (put only) and when a put instruction is used with read-only hardware (get only). ? reading (get) from write-only (put only) peripheral hardware will yield an unpredictable value. ? writing (put) to read-only (get only) peripheral hardware has no effect (regarded as a nop instruction). table 10-1. peripheral hardware (1) peripheral hardware with input/output in 8-bit units direction of data put get 01h siosfr shift register l l l l 8 bits 02h tmc timer count register l l 8 bits 03h tmm timer modulo register l l 8 bits (2) peripheral hardware with input/output in 16-bit units direction of data put get 40h ar address register l l l l 10 bits peripheral address name peripheral hardware peripheral address name peripheral hardware effective bit length effective bit length
chapter 10 data buffer (dbf) 82 10.2.2 data transfer with peripheral hardware data can be transferred between the data buffer and peripheral hardware in 8- or 16-bit units. instruction cycle for a single put or get instruction is the same regardless of whether eight or sixteen bits are being transferred. example 1. put instruction (when the effective bits in peripheral hardware are the 8 bits from 7 to 0) dbf0 b 0 b 1 b 2 b 3 data in peripheral hardware b 4 b 5 b 6 b 7 dbf2 don't care dbf3 don't care b 0 effective bits b 7 put dbf1 data buffer when only eight bits of data are being written from the data buffer, the upper eight bits of the data buffer (dbf3, dbf2) are irrelevant. example 2. get instruction (when the effective bits in peripheral hardware are the 8 bits from 7 to 0) when only eight bits of data are being read into the data buffer, the values in the upper eight bits of the data buffer (dbf3, dbf2) remain unchanged. dbf0 b 0 b 1 b 2 b 3 data in peripheral hardware b 4 b 5 b 6 b 7 dbf2 retained dbf3 retained b 0 effective bits b 7 get dbf1 data buffer
chapter 10 data buffer (dbf) 83 10.2.3 table reference by using the movt instruction, constant data in program memory (rom) can be read into the data buffer. the movt instruction is explained below. movt dbf, @ar: the contents of the program memory being pointed to by the address register (ar) is read into the data buffer (dbf). dbf3 dbf2 dbf1 dbf0 16 bits date buffer movt dbf, @ar program memory (rom) b 15 b 0
[memo] 84
chapter 11 arithmetic and logic unit the alu is used for performing arithmetic operations, logical operations, bit evaluations, comparison evaluations, and rotations on 4-bit data. 11.1 alu block configuration figure 11-1 shows the configuration of the alu block. as shown in figure 11-1, the alu block consists of the main 4-bit data processor, temporary registers a and b, the status flip-flop for controlling the status of the alu, and the decimal conversion circuit for use during arithmetic operations in bcd. as shown in figure 11-1, the status flip-flop consists of the following flags: zero flag ff, carry flag ff, compare flag ff, and the bcd flag ff. each flag in the status flip-flop corresponds directly to a flag in the program status word (psword: addresses 7eh, 7fh) located in the system register. the flags in the program status word are the following: zero flag (z), carry flag (cy), compare flag (cmp), and the bcd flag (bcd). 11.2 functions of the alu block arithmetic operations, logical operations, bit evaluations, comparison evaluations, and rotations are performed using the instructions in the alu block. table 11-1 lists each arithmetic/logical instruction, evaluation instruction, and rotation instruction. by using the instructions listed in table 11-1, 4-bit arithmetic/logical operations, evaluations and rotations can be performed in a single instruction. arithmetic operations in decimal can also be performed in a single instruction. 11.2.1 functions of the alu the arithmetic operations consists of addition and subtraction. arithmetic operations can be performed on the contents of the general register and data memory or on immediate data and the contents of data memory. operations in binary are performed on four bits of data operations in decimal are performed on one place (bcd operation). logical operations include anding, oring, and xoring. their operands can be general register contents and data memory contents, or data memory contents and immediate data. bit evaluation is used to determine whether bits in 4-bit data in data memory are 0 or 1. comparison evaluation is used to compare contents of data memory with immediate data. it is used to determine whether one value is equal to or greater than the other, less than the other, or if both values are equal or not equal. rotation is used to shift 4-bit data in the general register one bit in the direction of its least significant bit (rotation to the right). 85
chapter 11 arithmetic and logic unit 86 figure 11-1. configuration of the alu data bus temporary register a temporary register b status flip-flop alu ?arithmetic operations ?logical operations ?bit evaluations ?omparison evaluations ?otations decimal con- version circuit 7eh 7fh program status word (psword) b 0 bcd b 3 cmp b 2 cy b 1 z b 0 ixe status flip-flop cmp flag ff cy flag ff z flag ff bcd flag ff function outline indicates when the result of an arithmetic operation is 0. stores the borrow or carry from an arithmetic operation. used to indicate whether to store the result of an arithmetic operation. used to indicate whether to perform decimal correction for arithmetic operations. address name bit flag
chapter 11 arithmetic and logic unit 87 [memo]
chapter 11 arithmetic and logic unit 88 table 11-1. list of alu instructions (1/2) alu functions instruction operation explanation add r, m (r) ? (r) + (m) adds contents of general register and data memory. result is stored in general register. add m, #n4 (m) ? (m) + n4 adds immediate data to contents of data memory. result is stored in data memory. addc r, m (r) ? (r) + (m) + cy adds contents of general register, data memory and carry flag. result is stored in general register. addc m, #n4 (m) ? (m) + n4 + cy adds immediate data, contents of data memory and carry flag. result is stored in data memory. sub r, m (r) ? (r) C (m) subtracts contents of data memory from contents of general register. result is stored in general register. sub m, #n4 (m) ? (m) C n4 subtracts immediate data from data memory. result is stored in data memory. subc r, m (r) ? (r) C (m) C cy subtracts contents of data memory and carry flag from contents of general register. result is stored in general register. subc m, #n4 (m) ? (m) C n4 C cy subtracts immediate data and carry flag from data memory. result is stored in data memory. or r, m (r) ? (r) (m) or operation is performed on contents of general register and data memory. result is stored in general register. or m, #n4 (m) ? (m) n4 or operation is performed on immediate data and contents of data memory. result is stored in data memory. and r, m (r) ? (r) (m) and operation is performed on contents of general register and data memory. result is stored in general register. and m, #n4 (m) ? (m) n4 and operation is performed on immediate data and contents of data memory. result is stored in data memory. xor r, m (r) ? (r) (m) xor operation is performed on contents of general register and data memory. result is stored in general register. xor m, #n4 (m) ? (m) n4 xor operation is performed on immediate data and contents of data memory. result is stored in data memory. true skt m, #n cmp ? 0, if (m) n=n, skips next instruction if all bits in data memory then skip specified by n are true (1). result is not stored. false skf m, #n cmp ? 0, if (m) n=0, skips next instruction if all bits in data memory then skip specified by n are false (0). result is not stored. equal ske m, #n4 (m) C n4, skip if zero skips next instruction if immediate data equals contents of data memory. result is not stored. not skne m, #n4 (m) C n4, skip if not zero skips next instruction if immediate data is not equal equal to contents of data memory. result is not stored. 3 skge m, #n4 (m) C n4, skip if not borrow skips next instruction if contents of data memory is greater than or equal to immediate data. result is not stored. < sklt m, #n4 (m) C n4, skip if borrow skips next instruction if contents of data memory is less than immediate data. result is not stored. rotation rorc r rotate contents of the general register along with the cy flag to the right. result is stored in general register. bit judge- ment rotate to the right arith- metic opera- tions addi- tion sub- traction logical opera- tions logical or logical and logical xor cy ? (r) b3 ? (r) b2 ? (r) b1 ? (r) b0 com- parison judge- ment
chapter 11 arithmetic and logic unit 89 set if the operation result is 0000b; reset otherwise. the status is retained if the operation result is 0000b; reset otherwise. set if the operation result is 0000b; reset otherwise. the status is retained if the operation result is 0000b; reset otherwise. don't care don't care don't care don't care (held) (held) (held) (held) don't care don't care don't care (held) (held) (held) don't care don't care don't care don't care (held) (held) (held) (held) don't care don't care don't care (held) (held) (held) table 11-1. list of alu instructions (2/2) alu function operational variance depending on program status word (psword) cy flag z flag bcd flag's value cmp flag's value operating action modifica- tion by ixe=1 the binary operation result is stored. the bcd operation result is stored. the binary operation result is not stored. the bcd operation result is not stored. 00 01 10 11 set if a carry or borrow is generated; reset otherwise. yes arithmetic operation unchanged yes is reset unchanged yes unchanged yes unchanged yes logical operation bit judgement comparison judgement rotation general register b 0 's value .............. ................................................ ............. ...................... .............. ................................................ ............. ...................... .............. ................................................ ............. ...................... .............. ................................................ ............. ...................... ................................................ ............. ...................... .............. .............. ................................................ ............. ...................... .............. ................................................ ............. ......................
chapter 11 arithmetic and logic unit 90 11.2.2 functions of temporary registers a and b temporary registers a and b are needed for processing of 4-bit data. these registers are used for temporary storage of the first and second data operands of an instruction. 11.2.3 functions of the status flip-flop the status flip-flop is used for controlling operation of the alu and for storing data which has been processed. each flag in the status flip-flop corresponds directly to a flag in the program status word (psword) located in the system register. this means that when a flag in the system register is manipulated it is the same as manipulating a flag in the status flip-flop. each flag in the program status word is described below. (1) z flag this flag is set (1) when the result of an arithmetic operation is 0000b, otherwise it is reset (0). however, as described below, depending on the status of the cmp flag, the conditions which cause this flag to be set (1) can be changed. (i) when cmp=0 z flag is set (1) when the result of an arithmetic operation is 0000b, otherwise it is reset (0). (ii) when cmp=1 the previous state of the z flag is maintained when the result of an arithmetic operation is 0000b, otherwise it is reset (0). only affected by arithmetic operations. (2) cy flag this flag is set (1) when a carry or borrow is generated in the result of an arithmetic operation, otherwise it is reset (0). when an arithmetic operation is being performed using a carry or borrow, the operation is performed using the cy flag as the least significant bit. when a rotation (rorc instruction) is performed, the contents of the cy flag becomes the most significant bit (bit b 3 ) of the general register and the least significant bit of the general register is stored in the cy flag. only affected by arithmetic operations and rotations.
chapter 11 arithmetic and logic unit 91 (3) cmp flag when the cmp flag is set (1), the result of an arithmetic operation is not stored in either the general register or data memory. when the bit evaluation instruction is performed, the cmp flag is reset (0). the cmp flag does not affect comparison evaluations, logical operations, or rotations. (4) bcd flag when the bcd flag is set (1), decimal correction is performed for all arithmetic operations. when the flag is reset (0), decimal correction is not performed. the bcd flag does not affect logical operations, bit evaluations, comparison evaluations, or rotations. these flags can also be set through direct manipulation of the values in the program status word. when the flags in the program status word are manipulated, the corresponding flag in the status flip-flop is also manipulated. 11.2.4 performing operations in 4-bit binary when the bcd flag is set to 0, arithmetic operations are performed in 4-bit binary. 11.2.5 performing operations in bcd when the bcd flag is set to 1, decimal correction is performed for arithmetic operations performed in 4-bit binary. table 11-2 shows the differences in the results of operations performed in 4-bit binary and in bcd. when the result of an addition after decimal correction is equal to or greater than 20, or the result of a subtraction after decimal correction is outside of the range C10 to +9, a value of 1010b (0ah) or higher is stored as the result (shaded area in table 11-2).
chapter 11 arithmetic and logic unit 92 operation result addition in 4-bit binary addition in bcd operation result cy operation result cy 0 0 0000 0 0000 1 0 0001 0 0001 2 0 0010 0 0010 3 0 0011 0 0011 4 0 0100 0 0100 5 0 0101 0 0101 6 0 0110 0 0110 7 0 0111 0 0111 8 0 1000 0 1000 9 0 1001 0 1001 10 0 1010 1 0000 11 0 1011 1 0001 12 0 1100 1 0010 13 0 1101 1 0011 14 0 1110 1 0100 15 0 1111 1 0101 16 1 0000 1 0110 17 1 0001 1 0111 18 1 0010 1 1000 19 1 0011 1 1001 20 1 0100 1 1110 21 1 0101 1 1111 22 1 0110 1 1100 23 1 0111 1 1101 24 1 1000 1 1110 25 1 1001 1 1111 26 1 1010 1 1100 27 1 1011 1 1101 28 1 1100 1 1010 29 1 1101 1 1011 30 1 1110 1 1100 31 1 1111 1 1101 table 11-2. results of arithmetic operations performed in 4-bit binary and bcd operation result subtraction in 4-bit binary subtraction in bcd operation result cy operation result cy 0 0 0000 0 0000 1 0 0001 0 0001 2 0 0010 0 0010 3 0 0011 0 0011 4 0 0100 0 0100 5 0 0101 0 0101 6 0 0110 0 0110 7 0 0111 0 0111 8 0 1000 0 1000 9 0 1001 0 1001 10 0 1010 1 1100 11 0 1011 1 1101 12 0 1100 1 1110 13 0 1101 1 1111 14 0 1110 1 1100 15 0 1111 1 1101 C16 1 0000 1 1110 C15 1 0001 1 1111 C14 1 0010 1 1100 C13 1 0011 1 1101 C12 1 0100 1 1110 C11 1 0101 1 1111 C10 1 0110 1 0000 C9 1 0111 1 0001 C8 1 1000 1 0010 C7 1 1001 1 0011 C6 1 1010 1 0100 C5 1 1011 1 0101 C4 1 1100 1 0110 C3 1 1101 1 0111 C2 1 1110 1 1000 C1 1 1111 1 1001
chapter 11 arithmetic and logic unit 93 11.2.6 performing operations in the alu block when arithmetic operations, logical operations, bit evaluations, comparison evaluations or rotations in a program are executed, the first data operand is stored in temporary register a and the second data operand is stored in temporary register b. the first data operand is four bits of data used to specify the contents of an address in the general register or data memory. the second data operand is four bits of data used to either specify the contents of an address in data memory or to be used as an immediate value. for example, in the instruction add r, m second data operand first data operand the first data operand, r, is used to specify the contents of an address in the general register. the second data operand, m, is used to specify the contents of an address in data memory. in the instruction add m, #n4 the first data operand, m, is used to specify an address in data memory. the second operand, #n4, is immediate data. in the rotation instruction rorc r only the first data operand, r (used to specify the contents of an address in the general register) is used. next, using the data stored in temporary registers a and b, the alu executes the operation specified by the instruction (arithmetic operation, logical operation, bit evaluation, comparison evaluation, or rotation). when the instruction being executed is an arithmetic operation, logical operation, or rotation, the data processed by the alu is stored in the location specified by the first data operand (general register address or data memory address) and the operation terminates. when the instruction being executed is a bit evaluation or comparison evaluation, the result processed by the alu is used to determine whether or not to skip the next instruction (whether to treat next instruction as a no operation instruction: nop) and the operation terminates.
chapter 11 arithmetic and logic unit 94 caution should be taken with regard to the following points: (1) arithmetic operations are affected by the cmp and bcd flags in the program status word. (2) logical operations are not affected by the cmp or bcd flag in the program status word. logical operations do not affect the z or cy flags. (3) bit evaluation causes the cmp flag in the program status word to be reset. (4) when an arithmetic operation, logical operation, bit evaluation, comparison evaluation, or rotation is being executed and the ixe flag in the program status word is set (1), address modification is performed using the index register. 11.3 arithmetic operations (addition and subtraction in 4-bit binary and bcd) as shown in table 11-3, arithmetic operations consist of addition, subtraction, addition with carry, and subtraction with borrow. these instructions are add, addc, sub, and subc. the add, addc, sub, and subc instructions are further divided into addition and subtraction of the general register and data memory and addition and subtraction of data memory and immediate data. when the operands r and m are used, addition or subtraction is performed using the general register and data memory. when the operands m and #n4 are used, addition or subtraction is performed using data memory and immediate data. arithmetic operations are affected by the status flip-flop and the program status word (psword) in the system register. the bcd flag in the program status word is used to specify whether arithmetic operations are to be performed in 4-bit binary or in bcd. the cmp flag is used to specify whether or not the results of arithmetic operations are to be stored. 11.3.1 to 11.3.4 explain the relationship between each command and the program status word. table 11-3. types of arithmetic operations arithmetic addition without carry add general register and data memory add r, m operation data memory and immediate data add m, #n4 with carry addc general register and data memory addc r, m data memory and immediate data addc m, #n4 subtraction without borrow sub general register and data memory sub r, m data memory and immediate data sub m, #n4 with borrow subc general register and data memory subc r, m data memory and immediate data subc m, #n4
chapter 11 arithmetic and logic unit 95 11.3.1 addition and subtraction when cmp=0 and bcd=0 addition and subtraction are performed in 4-bit binary and the result is stored in the general register or data memory. when the result of the operation is greater than 1111b (carry generated) or less than 0000b (borrow generated), the cy flag is set (1); otherwise it is reset (0). when the result of the operation is 0000b, the z flag is set (1) regardless of whether there is carry or borrow; otherwise it is reset (0). 11.3.2 addition and subtraction when cmp=1 and bcd=0 addition and subtraction are performed in 4-bit binary. however, because the cmp flag is set (1), the result of the operation is not stored in either the general register or data memory. when there is a carry or borrow in the result of the operation, the cy flag is set (1); otherwise it is reset (0). when the result of the operation is 0000b, the previous state of the z flag is maintained; otherwise it is reset (0). 11.3.3 addition and subtraction when cmp=0 and bcd=1 bcd operations are performed. the result of the operation is stored in the general register or data memory. when the result of the operation is greater than 1001b (9d) or less than 0000b (0d), the carry flag is set (1), otherwise it is reset (0). when the result of the operation is 0000b (0d), the z flag is set (1), otherwise it is reset (0). operations in bcd are performed by first computing the result in binary and then by using the decimal conversion circuit to convert the result to decimal. for information concerning the binary to decimal conversion, refer to table 11-2 . in order for operations in bcd to be performed properly, note the following: (1) result of an addition must be in the range 0d to 19d. (2) result of a subtraction must be in the range 0d to 9d, or in the range C10d to C1d. the following shows which value is considered the cy flag in the range 0d to 19d (shown in 4-bit binary): 0, 0000b to 1, 0011b cy cy the following shows which value is considered the cy flag in the range C10d to C1d (shown in 4-bit binary): 1, 0110b to 1, 1111b cy cy when operations in bcd are performed outside of the limits of (1) and (2) stated above, the cy flag is set (1) and the result of operation is output as a value greater than or equal to 1010b (0ah).
chapter 11 arithmetic and logic unit 96 11.3.4 addition and subtraction when cmp=1 and bcd=1 bcd operations are performed. the result is not stored in either the general register or data memory. in other words, the operations specified by cmp=1 and bcd=1 are both performed at the same time. example mov rpl, #0001b ; sets the bcd flag (bcd=1). mov psw, #1010b ; sets the cmp and z flag (cmp=1, z=1) and resets the cy flag ; (cy=0). sub m1, #0001b ; <1> subc m2, #0010b ; <2> subc m3, #0011b ; <3> by executing the instructions in steps numbered <1>, <2>, and <3>, the twelve bits in memory locations m1, m2, and m3 and the immediate data (321) can be compared in decimal. 11.3.5 cautions on use of arithmetic operations when performing arithmetic operations with the program status word (psword), caution should be taken with regard to the result of the operation being stored in the program status word. normally, the cy and z flags in the program status word are set (1) or reset (0) according to the result of the arithmetic operation being executed. however, when an arithmetic operation is performed on the program status word itself, the result is stored in the program status word. this means that there is no way to determine if there is a carry or borrow in the result of the operation nor if the result of the operation is zero. however, when the cmp flag is set (1), results of arithmetic operations are not stored. therefore, even in the above case, the cy and z flags will be properly set (1) or reset (0) according to the result of the operation. 11.4 logical operations as shown in table 11-4, logical operations consist of logical or, logical and, and logical xor. accordingly, the logical operation instructions are or, and, and xor. the or, and, and xor instructions can be performed on either the general register and data memory, or on data memory and immediate data. the operands of these instructions are specified in the same way as for arithmetic operations ("r, m" or "m, #n4"). logical operations are not affected by the bcd or cmp flags in the program status word (psword). logical operations do not cause either the cy or z flag in the program status word (psword) to be set. however, when the index enable flag (ixe) is set (1), index modification is performed using the index register.
chapter 11 arithmetic and logic unit 97 table 11-4. logical operations logical logical or general register and data memory or r, m operation data memory and immediate data or m, #n4 logical and general register and data memory and r, m data memory and immediate data and m, #n4 logical xor general register and data memory xor r, m data memory and immediate data xor m, #n4 table 11-5. table of true values for logical operations logical and logical or logical xor c=a and b c=a or b c=a xor b a b c a b c a b c 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 111111110 11.5 bit judgement as shown in table 11-6, there are both true (1) and false (0) bit judgement instructions. the skt instruction skips the next instruction when a bit is judged as true (1) and the skf instruction skips the next instruction when a bit is judged as false (0). the skt and skf instructions can only be used with data memory. bit judgement are not affected by the bcd flag in the program status word (psword) and bit judgements do not cause either the cy or z flag in the program status word (psword) to be set. however, when an skt or skf instruction is executed, the cmp flag is reset (0). when the index enable flag (ixe) is set (1), index modification is performed using the index register. for information concerning index modification using the index register, refer to chapter 7 system register (sys reg) . 11.5.1 and 11.5.2 explain true (1) and false (0) bit judgements. table 11-6. bit judgement instructions bit judgement true (1) bit judgement skt m, #n false (0) bit judgement skf m, #n
chapter 11 arithmetic and logic unit 98 11.5.1 true (1) bit judgement the true (1) bit judgement instruction (skt m, #n) is used to determine whether or not the bits specified by n in the four bits of data memory m are true (1). when all bits specified by n are true (1), this instruction causes the next instruction to be skipped. example mov m1, #1011b skt m1, #1011b ; <1> br a br b skt m1, #1101b ; <2> br c br d in this example, bit 3, 1, and 0 of data memory m1 are judged in step number <1>. because all the bits are true (1), the program branches to b. in step number <2>, bits 3, 2 and 0 of data memory m1 are judged. since bit 2 of data memory m1 is false (0), the program branches to c. 11.5.2 false (0) bit judgement the false (0) bit judgement instruction (skf m, #n) is used to determine whether or not the bits specified by n in the four bits of data memory m are false (0). when all bits specified by n are false (0), this instruction causes the next instruction to be skipped. example mov m1, #1011b skt m1, #0110b ; <1> br a br b skt m1, #1101b ; <2> br c br d in this example, bits 2 and 1 of data memory m1 are judged in step number <1>. because both bits are false (0), the program branches to b. in step number <2> bits 3, 2, and 1 of data memory m1 are judged. since bit 3 of data memory m1 is true (1), the program branches to c.
chapter 11 arithmetic and logic unit 99 11.6 comparison judgement as shown in table 11-7, there are comparison judgement instructions for determining if one value is "equal to", "not equal to", "greater than or equal to", or "less than" another. the ske instruction is used to determine if two values are equal. the skne instruction is used to determine two values are not equal. the skge instruction is used to determine if one value is greater than or equal to another and the sklt instruction is used to determine if one value is less than another. the ske, skne, skge, and sklt instructions perform comparisons between a value in data memory and immediate data. in order to compare values in the general register and data memory, a subtraction instruction is performed according to the values in the cmp and z flags in the program status word (psword). for more information concerning comparison of the general register and data memory, refer to 11.3 . comparison judgements are not affected by the bcd or cmp flags in the program status word (psword) and comparison judgements do not cause either the cy or z flags in the program status word (psword) to be set. 11.6.1 to 11.6.4 explain the "equal to", "not equal to", "greater than or equal to", and "less than" comparison judgements. table 11-7. comparison judgement instructions comparison equal to judgement ske m, #n4 not equal to skne m, #n4 greater than or equal to skge m, #n4 less than sklt m, #n4
chapter 11 arithmetic and logic unit 100 11.6.1 "equal to" judgement the "equal to" judgement instruction (ske m, #n4) is used to determine if immediate data and the contents of a location in data memory are equal. this instruction causes the next instruction to be skipped when the immediate data and the contents of data memory are equal. example mov m1, #1010b ske m1, #1010b ; <1> br a br b ; ske m1, #1000b ; <2> br c br d in this example, because the contents of data memory m1 and immediate data 1010b in step number <1> are equal, the program branches to b. in step number <2>, because the contents of data memory m1 and immediate data 1000b are not equal, the program branches to c. 11.6.2 "not equal to" judgement the "not equal to" judgement instruction (skne m, #n4) is used to determine if immediate data and the contents of a location in data memory are not equal. this instruction causes the next instruction to be skipped when the immediate data and the contents of data memory are not equal. example mov m1, #1010b skne m1, #1000b ; <1> br a br b ; skne m1, #1010b ; <2> br c br d in this example, because the contents of data memory m1 and immediate data 1000b in step number <1> are not equal, the program branches to b. in step number <2>, because the contents of data memory m1 and immediate data 1010b are equal, the program branches to c.
chapter 11 arithmetic and logic unit 101 11.6.3 "greater than or equal to" judgement the "greater than or equal to" judgement instruction (skge m, #n4) is used to determine if the contents of a location in data memory is a value greater than or equal to the value of the immediate data operand. if the value in data memory is greater than or equal to that of the immediate data, this instruction causes the next instruction to be skipped. example mov m1, #1000b skge m1, #0111b ; <1> br a br b ; skge m1, #1000b ; <2> br c br d ; skge m1, #1001b ; <3> br e br f in this example, the program will first branch to b since the value in data memory is larger than that of the immediate data. next, it will branch to d since the value in data memory is equal to that of the immediate data. lastly it will branch to e since the value in data memory is less than that of the immediate data. 11.6.4 "less than" judgement the "less than" judgement instruction (sklt m, #n4) is used to determine if the contents of a location in data memory is a value less than that of the immediate data operand. if the value in data memory is less than that of the immediate data, this instruction causes the next instruction to be skipped. example mov m1, #1000b sklt m1, #1001b ; <1> br a br b ; sklt m1, #1000b ; <2> br c br d ; sklt m1, #0111b ; <3> br e br f in this example, the program will first branch to b since the value in data memory is less than that of the immediate data. next, it will branch to c since the value in data memory is equal to that of the immediate data. lastly it will branch to e since the value in data memory is greater than that of the immediate data.
chapter 11 arithmetic and logic unit 102 11.7 rotations there are rotation instructions for rotation to the right and for rotation to the left. the rorc instruction is used for rotation to the right. the rorc instruction can only be used with the general register. rotation using the rorc instruction is not affected by the bcd or cmp flags in the program status word (psword) and does not affect the z flag in the program status word (psword). rotation to the left is performed by using the addition instruction addc. 11.7.1 and 11.7.2 explain rotation. 11.7.1 rotation to the right the instruction used for rotation to the right (rorc r) rotates the contents of the general register in the direction of its least significant bit. when this instruction is executed, the contents of the cy flag becomes the most significant bit of the general register (bit 3) and the least significant bit of the general register is placed in the cy flag. example 1. mov psw, #0100b ; sets cy flag to 1. mov r1, #1100b rorc r1 when these instructions are executed, the following operation is performed. basically, when rotation to the right is performed, the following operation is executed: cy flag ? b 3 , b 3 ? b 2 , b 2 ? b 1 , b 1 ? b 0 , b ? cy flag. 2. mov psw, #0000b ; resets cy flag to 0. mov r1, #1000b mov r2, #0100b mov r3, #0010b rorc r1 rorc r2 rorc r3 the program code above rotates the 13 bits in cy, r1, r2 and r3 to the right. cy flag b 3 b 2 b 1 b 0 11100
chapter 11 arithmetic and logic unit 103 11.7.2 rotation to the left rotation to the left is performed by using the addition instruction, "addc r, m". example mov psw #0000b ; resets cy flag to 0. mov r1, #1000b mov r2, #0100b mov r3, #0010b addc r3, r3 addc r2, r2 addc r1, r1 the program code above rotates the 13 bits in cy, r1, r2 and r3 to the left.
[memo] 104
chapter 12 ports 12.1 port 0a (p0a 0 , p0a 1 , p0a 2 , p0a 3 ) port 0a is a 4-bit input/output port with an output latch. it is mapped into address 70h of bank0 in data memory. the output format is cmos push-pull output. input or output can be specified in each bit. input/output is specified by p0abio0 to p0abio3 (address 35h) in the register file. when p0abion is 0 (n=0 to 3), each pin of port 0a is used as input port. if a read instruction is executed for the port register, pin statuses are read. when p0abion is 1 (n=0 to 3), each pin of port 0a is used as output port and the contents written in the output latch are output to pins. if a read instruction is executed when pins are output ports, the contents of the output latch, rather than pin statuses, are fetched. at reset, p0abion is set to 0 and all p0a pins become input ports. the contents of the port output latch are 0. table 12-1. writing into and reading from the port register (0.70h) bank0 70h write read 0 input p0a pin status 1 output p0a latch contents p0abion rf: 35h pin input/output possible write to the p0a latch 105
chapter 12 ports 106 12.2 port 0b (p0b 0 , p0b 1 , p0b 2 , p0b 3 ) port 0b is a 4-bit input/output port with an output latch. it is mapped into address 71h of bank0 in data memory. the output format is cmos push-pull output. input or output can be specified in 4-bit units. input/output is specified by p0bgio (bit 0 at address 24h) in the register file. when p0bgio is 0, all pins of port 0b are used as input ports. if a read instruction is executed for the port register, pin statuses are read. when p0bgio is 1, all pins of port 0b are used as output ports. the contents written in the output latch are output to pins. if a read instruction is executed when pins are used as output ports, the contents of the output latch, rather than pin statuses, are fetched. at reset, p0bgio is 0 and all p0b pins are input ports. the value of the port 0b output latch is 0. table 12-2. writing into and reading from the port register (0.71h) bank0 71h write read 0 input p0b pin status 1 output p0b latch contents p0bgio rf: 24h, bit 0 pin input/output possible write to the p0b latch
chapter 12 ports 107 12.3 port 0c (p0c 0 , p0c 1 , p0c 2 , p0c 3 ) ... in the case of the m pd17120 and 17121 port 0c is a 4-bit input/output port with an output latch. it is mapped into address 72h of bank0 in data memory. the output format is cmos push-pull output. input or output can be specified bit-by-bit. input/output can be specified by p0cbio0 to p0cbio3 (address 34h) in the register file. if p0cbion is 0 (n=0 to 3), the p0cn pins are used as input port. if a data read instruction is executed for the port register, the pin statuses are read. if p0cbion is 1 (n=0 to 3), the p0cn pins are used as output port and the contents written in the output latch are output to pins. if a read instruction is executed when pins are used as output ports, the contents of the latch, rather than pin statuses, are fetched. at reset, p0cbio0 to p0cbio3 are 0 and all p0c pins are input ports. the contents of the port output latch are 0. table 12-3. writing/reading to/from port register (0.72h) ( m pd17120, 17121) (n=0 to 3) bank0 72h write read 0 input status of p0c pin 1 output contents of p0c latch p0cbion rf: 34h pin input/output possible write to the p0c latch
chapter 12 ports 108 12.4 port 0c (p0c 0 /cin 0 , p0c 1 /cin 1 , p0c 2 /cin 2 , p0c 3 /cin 3 ) ... in the case of the m pd17132, 17133, 17p132, and 17p133 port 0c is a 4-bit input/output port with an output latch. it is mapped into address 72h of bank0 in data memory. the output format is cmos push-pull output. input or output can be specified bit-by-bit. input/output is specified with p0cbio0 to p0cbio3 (address 34h) in the register file. if p0cnion is 0 (n=0 to 3), the each pin of p0c is used as input port. if a data read instruction is executed for the port register, the pin statuses are read. if p0cnion is 1 (n=0 to 3), the each pin of p0c is used as output port and the value written in the output latch are output to pins. if a data read instruction is executed when pins are used as output ports, the output latch value, rather than pin statuses, is fetched. port 0c can also be used as an analog input to the comparator. p0c0idi to p0c3idi (address 23h) in the register file are used to switch the port and analog input pin. if p0cnidi is 0 (n=0 to 3), the p0c n /cin n pin functions as a port. if p0cnidi is 1 (n=0 to 3), the p0c n /cin n pin functions as the analog input pin of the comparator. therefore, when using pins as analog inputs, 1 should be set to p0cnidi at the initial setting of the program. switching of the analog input pins to be compared is executed by cmpch0 and cmpch1 (rf: address 1ch). to use the pins as analog input pins of the comparator, set p0cbion=0 so that they are set as input ports (refer to 13.2 comparator ). at reset, p0cbion and p0cnidi are set to 0 (n=0 to 3) and all of port 0c pins become input ports. the contents of the port output latch become 0. table 12-4. writing into and reading from the port register (0.72h) and pin function selection (n=0 to 3) bank0 72h write read 0 input port pin state of p0c 1 output port contents of p0c latch 0 comparator analog input note 1 1 analog inputs of comparator and output contents of p0c port note 2 notes 1. this setting is ordinally selected when the pins are used as analog inputs of the comparator. 2. these pins function as an output port. at this time, the analog input voltage is changed by the effect of the output from the port. when using the pin as the analog input, be sure to set it to p0cbion=0. pin state of p0c write in the p0c latch function p0cnidi rf: 23h p0cbion rf: 34h 0 1
chapter 12 ports 109 12.5 port 0d (p0d 0 /sck, p0d 1 /so, p0d 2 /si, p0d 3 /tmout) port 0d is a 4-bit input/output port with an output latch. it is mapped into address 73h of bank0 in data memory. the output format is n-ch open-drain output. the mask option can be used to specify that a pin contain a pull-up resistor bit-by-bit note . input or output can be specified bit-by bit. input/output is specified with p0dbio0 to p0dbio3 (address 33h) in the register file. if p0dbion is 0 (n=0 to 3), the p0dn pins are used as input port. pin statuses are read if a data read instruction is executed for the port register. if p0dbion is 1, the p0dn pins are used as output port and the value written in the output latch are output to pins. if a data read instruction is executed when pins are used as output ports, the output latch value, rather than pin statuses, is fetched. at reset, p0dbion is set to 0 and all p0d pins become input ports. the contents of the port output latch become 0. the output latch contents remain unchanged even if p0dbion changes from 1 to 0. port 0d can also be used for serial interface input/output or timer output. sioen (0ah bit 0) in the register file is used to switch ports (p0d 0 to p0d 2 ) to serial interface input/output (sck, so, si) and vice versa. tmosel (bit 0 at address 12h) in the register file is used to switch a port (p0d 3 ) to timer output (tmout) and vice versa. if tmosel=1 is selected, 1 is output at timer reset. this output is inverted every time a timer count value matches the modulo register contents. note the m pd17p132 and 17p133 have no pull-up resistor by mask option.
chapter 12 ports 110 table 12-5. register file contents and pin functions (n=0 to 3) register file value pin function tmosel sioen p0dbion rf: 12h rf: 0ah rf: 33h p0d 0 /sck p0d 1 /so p0d 2 /si p0d 3 /tmout bit 0 bit 0 bit n 0 input port 1 output port 0 input port 1 output port 0 input port 1 output port 0 1 table 12-6. contents read from the port register (0.73h) port mode contents read from the port register (0.73h) input port pin status output port output latch contents an internal clock is selected as a serial clock. output latch contents an external clock is selected as a serial clock. pin status si pin status so not defined tmout output latch contents caution using the serial interface causes the output latch for the p0d 1 /so pin to be affected by the contents of the siosfr (shift register). so, reset the output latch before using the pin as output port. 0 1 0 1 0 1 sck so si sck so si tmout sck
chapter 12 ports 111 12.6 port 0e (p0e 0 , p0e 1 /v ref ) ... v ref ; m pd17132, 17133, 17p132, and 17p133 only port 0e is a 2-bit input/output port with an output latch. it is mapped into bits 0 and 1 of address 6fh in data memory. the output format is n-ch open-drain output. the mask option can be used to specify that a pin contain a pull-up resistor bit-by-bit. p0e 1 /v ref pin is also used as external reference voltage input of the comparator (incorporated only in the m pd17132, 17133, 17p132, and 17p133), and its function is changed from port to external reference voltage input depending on the value of the reference voltage selection resister. (cmpvref0 to cmpvref3) (refer to 13.2 comparator .) input or output can be specified bit-by-bit. input/output is specified with p0ebio0 and p0ebio1 (bits 0 and 1 at address 32h) in the register file. if p0ebion is 0 (n=0, 1), the each pin of p0e is used as input port. if a data read instruction is executed for the port register, the pin statuses are read. if p0ebion is 1 (n=0, 1), the each pin of p0e is used as output port and the value written in the output latch are output pins. if a data read instruction is executed regardless of the mode, the pin statuses, rather than output latch value, are fetched. at reset, p0ebion is set to 0 (n=0, 1) and each of port 0e pin become input port. the contents of the port output latch become 0. the write instruction to bits 2 and 3 at address 6fh becomes invalid. if the value is read, 0 is output. remark the m pd17p132 and 17p133 have no pull-up resistor by mask option. table 12-7. writing into and reading from the port registers (0.6fh.0, 0.6fh.1) (n=0, 1) bank01 6fh write read 0 input possible note write to the output latch p0e pin status of p0e note port register 6fh is a write only register. the data which is written during input mode (p0ebion=0) will be ignored. p0ebion rf: 32h pin input/ output 1 output
chapter 12 ports 112 12.6.1 cautions when operating port registers among the input/output ports in the m pd17120 series, only port 0e is such that, even when in output mode, doing a read causes the status of the pins to be read. consequently, when executing port register read macro instructions (setn/clrn, etc.) or bit manipulation instructions such as and/or/xor, etc., you may inadvertently change the status of the pins. be particularly careful when port 0e is being externally forced down to low level. figure 12-1 shows an example of the changes in the port register and microcontroller internal status when the clr1 p0e1 instruction (equivalent to the and 6f, #1101b instruction) is executed. for example, consider the case where both the p0e 1 and p0e 0 pins of port 0e are used for output, high level is output from pins p0e 1 and p0e 0 , and the p0e 0 pin is being externally forced down to a low level; then the status of each pin of port 0e is as shown in figure 12-1 <1>. the (p0e 3 and p0e 2 pins do not exist in the m pd17120 subseries, but are handled as if they exist in the program.) if the clr1 p0e1 instruction is executed to bring the p0e 1 pin to low level, the status of each pin of port 0e changes as shown in figure 12-1 <2>. in this case, the p0e 1 pin naturally changes to output low level, but the value of the port register changes so that pin p0e 0 , which should output high level, also outputs low level. this result comes about because the clr1 p0e1 instruction is executed not on the port register, but on the state of the pins. to avoid this phenomenon, use a mov or other instruction to set the state of all the pins, not just the pins that are to be changed. in this example, to set just the p0e 1 pin to a low level, you can use the mov 6fh, #1101 instruction, and the problem will not occur. for the same reason, when using port 0e for mixed input and output, be sure to put the pins that are being used for input into input mode (p0ebi0n = 0). figure 12-1. changes in port register due to execution of the clr1 p0e1 instruction p0e 3 does not exist p0e 2 p0e 1 1 h output h p0e 0 1 h output l (forced) execution of the clr1 p0e1 instruction [and 6fh, #1101b] port register microcomputer state pin state <1> before executing instructions p0e 3 does not exist p0e 2 p0e 1 0 l output l p0e 0 0 l output l port register microcomputer state pin state h: high level l: low level <2> after executing instructions
chapter 12 ports 113 12.7 port control register 12.7.1 input/output switching by group i/o ports which switch input/output in units of four bits are called group i/o. port 0b is used as group i/o. the register shown in the figure below is used for input/output switching. figure 12-2. input/output switching by group i/o rf: 24h read/write initial value when reset bit 3 0 0 r/w read=r, write=w p0bgio 0 1 function sets port 0b to input mode. sets port 0b to output mode. bit 2 0 0 bit 1 0 0 bit 0 p0bgio 0
chapter 12 ports 114 12.7.2 input/output switching by bit i/o ports which switch input/output bit-by-bit are called bit i/o. port 0a, port 0c, port 0d, and port 0e are used as bit i/o. the register shown in the figure below is used for input/output switching. figure 12-3. bit i/o port control register (1/4) rf: 35h read/write initial value when reset bit 3 p0abio3 0 r/w read=r, write=w p0abio0 0 1 function sets p0a 0 to input mode. sets p0a 0 to output mode. bit 2 p0abio2 0 bit 1 p0abio1 0 bit 0 p0abio0 0 p0abio1 0 1 function sets p0a 1 to input mode. sets p0a 1 to output mode. p0abio2 0 1 function sets p0a 2 to input mode. sets p0a 2 to output mode. p0abio3 0 1 function sets p0a 3 to input mode. sets p0a 3 to output mode.
chapter 12 ports 115 figure 12-3. bit i/o port control register (2/4) rf: 34h read/write initial value when reset bit 3 p0cbio3 0 r/w read=r, write=w p0cbio0 0 1 function sets p0c 0 to input mode. sets p0c 0 to output mode. bit 2 p0cbio2 0 bit 1 p0cbio1 0 bit 0 p0cbio0 0 p0cbio1 0 1 function sets p0c 1 to input mode. sets p0c 1 to output mode. p0cbio2 0 1 function sets p0c 2 to input mode. sets p0c 2 to output mode. p0cbio3 0 1 function sets p0c 3 to input mode. sets p0c 3 to output mode.
chapter 12 ports 116 figure 12-3. bit i/o port control register (3/4) rf: 33h read/write initial value when reset bit 3 p0dbio3 0 r/w read=r, write=w p0dbio0 0 1 function sets p0d 0 to input mode. sets p0d 0 to output mode. bit 2 p0dbio2 0 bit 1 p0dbio1 0 bit 0 p0dbio0 0 p0dbio1 0 1 function sets p0d 1 to input mode. sets p0d 1 to output mode. p0dbio2 0 1 function sets p0d 2 to input mode. sets p0d 2 to output mode. p0dbio3 0 1 function sets p0d 3 to input mode. sets p0d 3 to output mode. figure 12-3. bit i/o port control register (4/4) rf: 32h read/write initial value when reset bit 3 0 0 r/w read=r, write=w p0ebio0 0 1 function sets p0e 0 to input mode. sets p0e 0 to output mode. bit 2 0 0 bit 1 p0ebio1 0 bit 0 p0ebio0 0 p0ebio1 0 1 function sets p0e 1 to input mode. sets p0e 1 to output mode.
chapter 13 peripheral hardware 13.1 8-bit timer counter (tm) the m pd17120 subseries contains an 8-bit timer counter system. control of the 8-bit timer counter is performed through hardware manipulation using the put/get instruction or through register manipulation on the register file using the peek/poke instruction. 13.1.1 8-bit timer counter configuration figure 13-1 shows the configuration of the 8-bit timer counter. the 8-bit timer counter consists of the comparator, which compares the 8-bit count register, 8-bit modulo register, count register, and modulo register values; and the separator, which selects the count pulse. caution the modulo register is for writing only. the count register is for reading only. 117
chapter 13 peripheral hardware 118 figure 13-1. configuration of the 8-bit timer counter tmosel p0dbio3 timer modulo register (8) (tmm) timer comparator (8) p0d 3 output latch interrupt control register (rf : 0fh) int timer mode register (rf : 11h) tmres tmen tmck1 tmck0 internal bus timer carry output control mode register (rf : 12h) bit i/o port control register (rf : 33h) match reset clear p0d 3 / tmout irqtm set signal irqtm clear signal latch f x /32 f x /256 f x /2048 selector d clk r reset int internal reset 2 timer count register (8) (tmc) data buffer (dbf) tmout ff q
chapter 13 peripheral hardware 119 13.1.2 8-bit timer counter control register there are two types of 8-bit timer counter control registers; timer mode register and timer carry output control mode register. figures 13-2 and 13-3 show the configuration of 8-bit timer counter control registers. figure 13-2. timer mode register rf: 11h read/write initial value when reset bit 3 tmen 1 bit 2 tmres 0 bit 1 tmck1 0 bit 0 tmck0 0 r/w read=r, write=w tmck1 0 0 1 1 source clock selection f x /256 f x /32 f x /2048 external clock from int pin tmres 0 1 tmck0 0 1 0 1 timer reset no influence to timer reset count register (tmc) and irqtm remark tmres is automatically cleared (0) when set (1). when reading it, 0 is always read. tmen 0 1 timer start instruction stop timer counting. start timer counting. remark tmen can be used as the status flag which detects the count state of the timer (0 : count stop, 1 : counting).
chapter 13 peripheral hardware 120 13.1.3 operation of 8-bit timer counters (1) count register count register are 8-bit up counters whose initial values are 00h. they are incremented each time a count pulse is entered. the counter register is initialized in the following situations: ? when the microcontroller is reset (refer to chapter 6 reset ); ? when the content of the 8-bit modulo register coincides with the count register value, thus causing the comparator to generate the relevant signal; and ? when "1" is written in the tmres of the register file. (2) modulo register the modulo registers determine the count value of count register. they are initialized to ffh. a value is set in a modulo register via the data buffer (dbf) using the put instruction. (3) comparator the comparators output match signals when the value of the count register and modulo register match and when the next count pulse is input. that is, if the value of the modulo register is initial value ffh, the comparator outputs a match signal when 256 is counted. the match signal from the comparator clears the contents of the count register to 0 and automatically sets the interrupt request flag (irqtm) to 1. at this time interrupt handling occurs if the ei instruction (interrupt acceptance enable instruction) is executed and also the interrupt enable flag (iptm) is set. when an interrupt is accepted, the interrupt request flag (irqtm) is set to 0 and program control transfers to the interrupt handling routine. 13.1.4 selecting count pulse a count pulse is selected with tmck0 or tmck1. one system clock f x can be selected from four types: a 2048-count pulse, 256-count pulse, 32-count pulse, and an external count pulse input from the int pin. at reset, tmck0 and tmck1 are 0 and f x /256 is selected. at power start-up or reset, timer is used to generate stabilization wait time. for this purpose, the initial values are tmck0=0 and tmck1=0 and f x /256 is selected. since the initial value is set to tmen=1, the system starts at address 0000h after 8 ms after reset at f x =8 mhz (32 ms at f x =2 mhz). (refer to chapter 16 reset .)
chapter 13 peripheral hardware 121 13.1.5 setting a count value in modulo register and calculation method count value is set in the module register via the data buffer (dbf). (1) setting the count value in modulo register a count value is set in the modulo register via the data buffer using the put instruction. the peripheral address of the modulo register is 03h. when a value is sent by the put instruction, data in the eight low-order bits (dbf1 and dbf0) of data buffer is sent to the modulo register. figure 13-3 shows an example of count value setting.
chapter 13 peripheral hardware 122 figure 13-3. setting the count value in a modulo register example of setting count value 64h in timer modulo register contdatl dat 4h ; contdatl is assigned to 4h using the symbol definition instruction. contdath dat 6h ; contdath is assigned to 6h using the symbol definition instruction. mov dbf0, #contdatl; mov dbf1, #contdath; put tmm, dbf ; the value is transferred with reserved word tmm. caution the range of values that can be set in the module register is 01h to ffh. if 00h is set, normal counting operation is not performed. the modulo register is for writing only. if is not possible to read a value from the modulo register. neither is it possible, while the 8-bit timer counter is in operation, to stop the counting operation even by executing the put tmm and dbf instructions. data buffer dbf3 don't care 8-bit data put tmm, dbf tmm (peripheral address 03h) b 7 0 b 5 1 b 4 0 b 3 0 b 2 1 b 1 0 b 0 0 b 6 1 b 0 0 b 1 0 b 2 1 b 3 0 b 0 0 b 1 1 b 2 1 b 3 0 b 0 b 1 b 2 b 3 b 0 b 1 b 2 b 3 dbf2 don't care dbf1 dbf0
chapter 13 peripheral hardware 123 (2) calculation method of count value the time interval of the identity signal being emitted from the comparator is determined by the value that is set in the modulo register. the formula for finding the value n of the modulo register from the time interval t [sec] is shown below: t= = (n+1) t cp n=t f cp C1 or n= C1 (n=1 to 255) f cp : count pulse's frequency [hz] t cp : count pulse's frequency [sec] (1/f cp = resolution) (3) calculation example and program example when calculating count value by interval time ? example of assuming 7 ms as interval time for timer (system clock: f x =8 mhz) assuming 7 ms as interval time, it is impossible to set 7 ms interval time from the resolution of the timer. therefore, count value should be calculated by selecting the source clock the resolution of which is maximum (f x /256, resolution: 32 m s) to set the nearest interval time. example t=7 ms, resolution: 32 m s n= C1 =C1 = 217.75=218 (: dah) the value of modulo register the interval time of which becomes nearest to 7 ms is dah, and the interval time at that time becomes 7.008 ms. f cp n+1 t t cp t (resolution) 7 10 C3 32 10 C5
chapter 13 peripheral hardware 124 (program example) mov dbf0, #0ah ; stores dah to dbf by using mov dbf1, #0dh ; reserved words "dbf0" and "dbf1" put tmm, dbf ; transfers the contents of dbf by using reserved word "tmm" initflg tmen, tmres, not tmck1, not tmck0 ; sets tmen and tmres by using built-in macro instruction "initflg". ; sets source clock of timer to "f x /256", and starts counting. 13.1.6 margin of error of interval time it is possible for the interval time to generate a margin of error of up to C1.5 counts. be careful if set value of the modulo register is small. (1) error (up to C1 count) when the count register is cleared to 0 during counting the count register of the 8-bit timer counter is cleared to 0 by setting (to 1) the tmres flag. however, the scaler for generating the count pulse from the system clock is not reset. therefore, if, during counting, the tmres flag is set (to 1) to clear the count to 0, an error margin of one cycle of the count pulse is generated in the timing of the first count. a count example when setting the modulo register to 2 is shown below: figure 13-4. error in zero-clearing the count register during counting in the example above, the identity signal is generated every three counts. however, only for the first time after the count is cleared, the identity signal is generated for the minimal 2 counts. the above error occurs not only when tmen=1 ? 0 but when tmres ? 1. count clear (tmres ? 0) count pulse count register 2 to 3 counts match signal output 112 0 2
chapter 13 peripheral hardware 125 (2) error in starting counting from the count halt state the count register of the 8-bit timer counter is cleared to zero by setting (to 1) the tmres flag; however, the scaler for generating the count pulse from the system clock is not reset. when the tmen flag is set (to 1) to start the counting from the count halt status, the timing of the first count varies as follows depending on whether the count pulse is started from the low level or from the high level. when started from the high level: the next rising edge is the first count when started from the low level: the count starting point is the first count therefore, only the first count after the counting is started generates an error of C0.5 to C1.5 counts during the time until the identity signal is issued. an example of counting when 1 is set for the modulo register is shown below. figure 13-5. error in starting counting from the count halt state (a) when the count pulse is stated from the high level (error: C0.5 to C1 count) counting start (tmen = 1 ? 0) match signal output 1 to 1.5 count 2 counts match signal output count pulse count register 0 0 1 1
chapter 13 peripheral hardware 126 (b) when the count pulse is started from the low level (error: C1 to C1.5 counts) in the example above, the identity signal is generated every 2 counts; however, only for the first count, the identity signal is issued for 1.5 counts maximum and for 0.5 count minimum (error: C0.5 to C1.5 counts). as the timer is in use even for generation of the oscillation stability wait time, the error margin above occurs even to this oscillation stability wait time. 13.1.7 reading count register values (1) reading counter values the counter values of count register are read at the same time via dbf (data buffer) using the get instruction. the count register values of timer are assigned to peripheral address 02h. count register values of timer can be read into dbf by using the get instruction. during execution of the get instruction, timer count register stops count operation and a count value is retained. when a count pulse enters the timer in use during execution of the get instruction, the count is retained. after execution of the get instruction, the count register increments by one and continues counting. the scheme prevents miscounting as long as two or more count pulses are not input in one instruction cycle, even when the get instruction is executed during timer operation. counting start (tmen = 1 ? 0) match signal output 2 counts match signal output 0.5 to 1count count pulse count register 0 0 1 1 0
chapter 13 peripheral hardware 127 figure 13-6. reading 8-bit counter count values the timer counter value is f0h. get dbf, tmc; example of using reserved words dbf and tmc data buffer dbf3 retained 8-bit data get dbf, tmc b 7 1 b 5 1 b 4 1 b 3 0 b 2 0 b 1 0 b 0 0 b 6 1 b 0 0 b 1 0 b 2 0 b 3 0 b 0 1 b 1 1 b 2 1 b 3 1 b 0 b 1 b 2 b 3 b 0 b 1 b 2 b 3 dbf2 retained dbf1 dbf0 tmc (peripheral address 02h) count value (2) program example ? measuring pulse width input from int pin (system clock: f x =8 mhz) the following is an example of measuring generation interval of external interrupt from int pin by using timer. at this time the pulse width from int pin should be within the count-up time of timer. (program example) cnttmh mem 0.30h ; symbol definition of save area of count value cnttml mem 0.31h ; org 00h ; specifies vector address of interrupt br main ; org 03h ; br intjob ; : : : : initial: initflg ip, not iptm, not ipsio ; prohibits interrupts other than external interrupt
chapter 13 peripheral hardware 128 initflg not iegmd1, iegmd0 ; sets input from int pin to falling edge clr1 irq ; clears interrupt request signal from int pin initflg tmem, tmres, not tmck1, tmck0 ; sets source clock of timer to "f x /32" ; clears timer count register and irqtm, ; and starts timer ei loop: br loop br tmrestart intjob: ; vector interrupt becomes interrupt prohibit get dbf, tmc ; state automatically immediately after accepting ; interrupt mov rph, #.dm. (cnttmh shr 7) and 0eh ; sets general register pointer by using ; symbol-defined "cnttmh" and "cnttml" and rpl, #0001b ; or rpl, # .dm. (cnttmh shr 3) and 0eh ; at this time, bcd flag retains the previous state ld cnttmh, dbf1 ; stores count value to count save area ld cnttml, dbf0 ; ei ; makes interrupt permit state when executing ; main processing program reti ; returns to main processing program
chapter 13 peripheral hardware 129 13.1.8 timer output the p0d 3 /tmout pin functions as a timer match signal output pin when the tmosel flag is set to 1. the p0dbio3 value has nothing to do with this setting. timer contains a match signal output flip-flop. it reverses the output each time the comparator outputs a match signal. when the tmosel flag is set to 1, the contents of this flip-flop are output to the p0d 3 /tmout pin. the p0d 3 /tmout pin is an n-ch open-drain output pin. the mask option enables this pin to contain a pull-up resistor. if this pin does not contain a pull-up resistor, its initial status is high impedance. an internal timer output flip-flop starts operating when tmen is set to 1. to make the flip-flop start output beginning at an initial value, set 1 in tmres and reset the flip-flop. remark the m pd17p132 and 17p133 have no mask option resistor. figure 13-7. timer output control mode register rf: 12h read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 0 0 bit 0 tmosel 0 r/w read=r, write=w timer output control p0d 3 /tmout pin functions as port. p0d 3 /tmout pin functions as timer match signal output. tmosel 0 1
chapter 13 peripheral hardware 130 13.1.9 timer resolution and maximum setting time table 13-1 shows the timer resolution in each source clock and maximum setting time. table 13-1. timer resolution and maximum setting time mode register timer tmck1 tmck0 resolution maximum setting time 0 0 32 m s 8.192 ms 0 1 4 m s 1.024 ms 1 0 256 m s 65.536 ms 1 1 int pin note 2 0 0 approx. 61.1 m s approx. 15.6 ms 0 1 approx. 7.64 m s approx. 1.9 ms 1 0 approx. 489 m s approx. 125 ms 1 1 int pin note 2 0 0 128 m s 32.768 ms 0 1 16 m s 4.096 ms 1 0 1.024 ms 262.144 ms 1 1 int pin note 2 0 0 512 m s 131.072 ms 0 1 64 m s 16.384 ms 1 0 4.096 ms 1.048576 s 1 1 int pin note 2 notes 1. the guaranteed frequency range of oscillation for the m pd17120/17132/17p132 is f cc =400 khz to 2.4 mhz. 2. high/low level width of int pin is 10 m s (min.) when v dd =4.5 to 5.5 v, and 50 m s (min.) when v dd =2.7 to 5.5 v. refer to data sheet for detailed information. system clock at 8 mhz note1 at 4.19 mhz note1 at 2 mhz at 500 khz
chapter 13 peripheral hardware 131 13.2 comparator ( m pd17132, 17133, 17p132, and 17p133 only) the comparator of the m pd17132, 17133, 17p132, and 17p133 compares the analog input (cin 0 to cin 3 ) and reference voltage (external: 1 type, internal: 15 types) and stores the comparison result to cmprslt (rf: 1eh, bit 0). the comparator can also be used as a 4-bit a/d converter by software using 15 types of internal reference voltage. 13.2.1 configuration of comparator figure 13-8. configuration of comparator remark the sampling time of an analog input is as follows: m pd17132, 17p132: 8/f cc (4 m s, at 2 mhz) m pd17133, 17p133: 28/f x (3.5 m s, at 8 mhz) rf : 1ch cmpch1 cmpch1 0 0 rf : 1dh cmpvref1 cmpvref2 rf : 1eh cmpstrt cmprslt 0 0 selector control circuit selector poc 0 /cin 0 poc 1 /cin 1 poc 2 /cin 2 poc 3 /cin 3 comparator cmpvref0 cmpvref3 internal bus r r 16 r poe 1 /v ref 100pf max. +
chapter 13 peripheral hardware 132 13.2.2 functions of comparator the comparator has a 4-channel analog input. concerning the pins used as analog input of the comparator, set 1 to p0cnidi (n=0 to 3) at initial setting of the program (refer to chapter 12 ports ). one of analog inputs (cin 0 to cin 3 ) can be selected by the comparator input channel selection flag (cmpch1, cmpch0 rf: 1ch, bits 1 and 0). one of the 16 types of reference voltages (external: 1, internal: 15) can be selected by the comparator reference voltage selection flag (cmpvref0 to cmpvref3 rf: 1dh). after setting the comparator start flag to 1 (cmpstrt rf: 1eh, bit 1), comparison takes 2 instruction execution cycles in the m pd17132 and 17p132, and 6 cycles in the m pd17133 and 17p133. a comparison result is stored to the comparator comparison result flag (cmprslt rf: 1eh, bit 0). whether the comparator is operating or comparison is completed can be known by reading comparator start flag. cmpstrt=1... comparator is operating (during analog voltage comparison) cmpstrt=0... comparator is stopped (comparison is completed) when comparing comparator analog voltage (cmpstrt=1), manipulating comparator input channel selection flag (cmpch1 cmpch0) or comparator reference voltage selection flag (cmpvref0 to cmpvref3) is ignored and the data in these registers remain unchanged. therefore, changing comparator operation modes are disabled. cmpstrt is cleared only when the voltage comparison operation of comparator is completed or when stop instruction is executed. caution when using the standby function, be sure to wait for the comparator operation to stop before executing a standby instruction (halt/stop). if a stop or halt instruction is executed while the comparator is in operation, the comparator operation is halted. if the internal reference voltage has been selected at this time, current will keep flowing into the internal resistor ladder, thus resulting in increased current consumption during standby mode. comparator input channel selection register, reference voltage selection register, and comparator operation control register are shown in the figures 13-9, 13-10, and 13-11, respectively.
chapter 13 peripheral hardware 133 figure 13-9. comparator input channel selection register rf: 1ch read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 cmpch1 0 bit 0 cmpch0 0 r/w read=r, write=w cmpch1 0 0 1 1 comparator input channel selection select cin 0 select cin 1 select cin 2 select cin 3 cmpch0 0 1 0 1 figure 13-10. reference voltage selection register rf: 1dh read/write initial value when reset bit 3 cmpvref3 1 bit 2 cmpvref2 0 bit 1 cmpvref1 0 bit 0 cmpvref0 0 r/w read=r, write=w selected reference voltage voltage applied to v ref pin 1/16 v dd 2/16 v dd (1/8 v dd ) 3/16 v dd 4/16 v dd (1/4 v dd ) 5/16 v dd 6/16 v dd (3/8 v dd ) 7/16 v dd 8/16 v dd (1/2 v dd ) 9/16 v dd 10/16 v dd (5/8 v dd ) 11/16 v dd 12/16 v dd (3/4 v dd ) 13/16 v dd 14/16 v dd (7/8 v dd ) 15/16 v dd cmpvref2 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 cmpvref3 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 cmpvref1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 cmpvref0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 caution when cmpstrt =1, a write instruction to this register is ignored (the data in the register remains unchanged).
chapter 13 peripheral hardware 134 figure 13-11. comparator operation control register rf: 1eh read/write initial value when reset read = r, write = w comparator operation comparison result when the voltage from analog input (cin 0 to cin 3 ) is lower than the external/internal reference voltage when the voltage from analog input (cin 0 to cin 3 ) is higher than the external/internal reference voltage cmpstrt 0 1 cmprslt 0 1 comparator operation check (at reading) comparator operation start (at writing) during comparator operation is stopped or comparator voltage comparison operation is completed during comparator is operating invalid start comparator operation remark cmpstrt is cleared to 0 only when the comparator voltage com- parison operation is completed or stop instruction is executed. cmpstrt 0 1 bit 3 0 0 bit 2 0 r/w 0 bit 1 cmpstrt 0 bit 0 cmprslt r 1
chapter 13 peripheral hardware 135 13.3 serial interface (sio) the serial interfaces of the m pd17120 subseries consists of a shift register (siosfr, 8 bits), serial mode register, and serial clock counter. it is used for serial data input/output. 13.3.1 functions of the serial interface this serial interface provides three signal lines: serial clock input pin (sck), serial data output pin (so), and serial data input pin (si). it allows 8 bits to be sent or received in synchronization with clocks. it can be connected to peripheral input/output devices using any method with a mode compatible to that used by the m pd7500 or 75x series. (1) serial clock three types of internal clocks and one type of external clock can be selected. if an internal clock is selected as a serial clock, it is automatically output to the p0d 0 /sck pin. table 13-2. list of serial clock siock1 siock0 serial clock to be selected 0 0 external clock from the sck pin 0 1 f x /16 1 0 f x /128 11f x /1024 (2) transmission operation by setting (to 1) sioen, each pin of port 0d (p0d 0 /sck, p0d 1 /so, p0d 2 /si) functions as a pin for serial interfacing. at this time, if siots is set (to 1), the operation is started synchronously with the falling edge of the serial clock. also, setting siots will result in automatically clearing irqsio. the transfer is started from the most significant bit of the shift register synchronously with the falling edge of the serial clock. and, the information on the si pin is stored in the shift register from the most significant bit, synchronously with the rising edge of the clock. if the 8-bit data transfer is terminated, siots is automatically cleared and irqsio is set. remark serial transmission starts only from the most significant bit of the shift register contents. it is not possible to transmit from the least significant bit. si pin status is always stored in the shift register in synchronization with the rising edge of the serial clock.
chapter 13 peripheral hardware 136 figure 13-12. block diagram of the serial interface note the output latch of the shift register is common with the output latch of p0d 1 . therefore, if an output instruction is executed for p0d 1 , the output latch state of the shift register is also changed. p0d 2 /si lsb msb p0d 1 /so serial start siots siock1 siock0 siohiz irqsio clear signal irqsio set signal carry clear serial clock counter clock p0d 0 /sck f x /1024 f x /128 f x /16 sioen p0dbio0 p0dbio1 shift register (siosfr) q s r selector selector output latch output latch note one shot
chapter 13 peripheral hardware 137 13.3.2 3-wire serial interface operation modes two modes can be used for the serial interface. if the serial interface function is selected, the p0d 2 /si pin always takes in data in synchronization with the serial clock. ? 8-bit send/receive mode (concurrent send/receive) ? 8-bit receive mode (so pin: high-impedance state) table 13-3. serial interface's operation mode sioen siohiz p0d 2 /si pin p0d 1 /so pin serial interface operation mode 1 0 si so 8-bit send/receive mode 1 1 si p0d 1 (input) 8-bit receive mode 0 p0d 2 (input/output) p0d 1 (input/output) general-purpose port mode : don't care (1) 8-bit transmission and reception mode (simultaneous transmission and reception) serial data input/output is controlled by a serial clock. the msb of the shift register is output from the so line with a falling edge of the serial clock (sck). the contents of the shift register is shifted one bit and at the same time, data on the si line is loaded into the lsb of the shift register. the serial clock counter counts serial clock pulses. every time it counts eight clocks, the interrupt request flag is set (irqsio ? 1). figure 13-13. timing of 8-bit transmission and reception mode (simultaneous transmission reception) 1234 5678 di7 di6 di5 di4 di3 di2 di1 di0 do7 do6 do5 do4 do3 do2 do1 do0 sck pin so pin irqsio si pin transmission starts in synchronization with the sck pin falling edge. an instruction which writes 1 into siots is executed. (transmission start indication) transmission completion remark din : serial input data don : serial output data
chapter 13 peripheral hardware 138 (2) 8-bit receive mode (so pin: high impedance state) when siohiz=1, the p0d 1 /so pin is placed in the high-impedance state. at this time, if "1" is written into siots to start supply of the serial clock, the serial interface operates only the receiving function. because the p0d 1 /so pin is placed in the high-impedance state, it can be used as an input port (p0d 1 ). figure 13-14. timing of the 8-bit reception mode high impedance 12345678 di7 di6 di5 di4 di3 di2 di1 di0 sck pin so pin irqsio si pin transmission starts in synchronization with the sck pin falling edge. an instruction which writes 1 into siots is executed. (transmission start indication) transmission completion remark din: serial input data (3) operation stop mode if the value in siots (rf: address 1ah, bit 3) is 0, the serial interface enters operation stop mode. in this mode, no serial transfer occurs. in this mode, the shift register does not perform shifting and can be used as an ordinary 8-bit register.
chapter 13 peripheral hardware 139 figure 13-15. serial interface control register (1/2) rf: 1ah read = r, write = w siock1 0 0 1 1 siock0 0 1 0 1 serial clock selection external clock (sck pin) f x /16 f x /128 f x /1024 function selection of the p0d 1 /so pin serial data output (so pin) input port (p0d 1 pin) confirmation of shift register operation status (at reading) the shift register is in the stop status. the shift register is operating. start and stop of serial transmission (at writing) forced termination of the shift register. disables intermediate restart. start of shift register operation ?at internal clock selection starts operating internal devided signal of a system clock (f x ) as a serial clock ?at external clock selection starts operation in synchronization with an sck pin falling edge. siohiz 0 1 siots 0 1 remark siots is automatically cleared to 0 when serial transmission is completed. read/write initial value when reset bit 3 siots 0 bit 2 siohiz 0 bit 1 siock1 0 bit 0 siock0 0 r/w siots 0 1
chapter 13 peripheral hardware 140 figure 13-15. serial interface control register (2/2) rf: 0ah read/write initial value when reset bit 3 0 0 r/w read = r, write = w bit 2 0 0 bit 1 0 0 bit 0 sioen 0 sioen 0 1 serial interface enable the pins of port 0d (p0d 0 /sck, p0d 1 /so, p0d 2 /si) function as the serial interface. the pins of port 0d (p0d 0 /sck, p0d 1 /so, p0d 2 /si) function as ports. remark refer to chapter 12 ports
chapter 13 peripheral hardware 141 13.3.3 setting values in the shift register values are set in the shift register via the data buffer (dbf) using the put instruction. the peripheral address of the shift register is 01h. when sending a value to the shift register using the put instruction, only the low-order eight bits (dbf1, dbf0) of dbf are valid. the dbf3 and dbf2 values do not affect the shift register. figure 13-16. setting a value in the shift register example of setting value 64h in the shift register siodatl dat 4h ; siodatl is assigned to 4h using symbol definition. siodath dat 6h ; siodath is assigned to 6h using symbol definition. mov dbf0, #siodatl ; mov dbf1, #siodath ; put siosfr, dbf ; value is transmitted using reserved word siosfr. put siosfr,dbf siosfr (peripheral address 01h) data buffer dbf3 don't care 8-bit data b 7 0 b 5 1 b 4 0 b 3 0 b 2 1 b 1 0 b 0 0 b 6 1 b 0 0 b 1 0 b 2 1 b 3 0 b 0 0 b 1 1 b 2 1 b 3 0 b 0 b 1 b 2 b 3 b 0 b 1 b 2 b 3 dbf2 don't care dbf1 dbf0
chapter 13 peripheral hardware 142 13.3.4 reading values from the shift register a value is read from the shift register via the data buffer (dbf) using the get instruction. the shift register has peripheral address 01h and only the eight low-order bits (dbf1, dbf0) are valid. executing the get instruction does not affect the eight high-order bits of dbf. figure 13-17. reading a value from the shift register get dbf, siosfr; example of using reserved words dbf and siosfr get dbf, siosfr siosfr (peripheral address 01h) data buffer dbf3 retained 8-bit data b 7 0 b 5 1 b 4 0 b 3 0 b 2 1 b 1 0 b 0 0 b 6 1 b 0 0 b 1 0 b 2 1 b 3 0 b 0 0 b 1 1 b 2 1 b 3 0 b 0 b 1 b 2 b 3 b 0 b 1 b 2 b 3 dbf2 retained dbf1 dbf0
chapter 13 peripheral hardware 143 13.3.5 program example of serial interface (1) program example of data transmission/reception by 8-bit transmission/reception mode (synchronous transmission/reception) this program executes data transmission/reception synchronizing with f x /128. judgment of finishing serial data transmission/reception is executed by checking interrupt request flag. example main: call siojob br main siojob: di ; prohibits interrupt in siojob clr1 irqsio ; clears interrupt request flag of sio set1 sioen ; enables sio mov dbf0, #siodatl ; sets transmitted data mov dbf1, #siodath put siosfr, dbf initflg siots, not siohiz, siock1, not siock0 ; sets serial clock to "f x /128", starts shift ; register operation, and outputs serial data loop: skt1 irqsio ; transmission/reception finish judgment br loop ; waits finishing transmission/reception get dbf, siosfr ; reads reception data ei ; permits interrupt and returns to main processing ret ; . . . . . . . .
chapter 13 peripheral hardware 144 (2) program example of data reception by 8-bit reception mode this program executes data reception synchronizing with external clock, and reads reception data by using interrupt processing. example siodath mem 0.50h siodatl mem 0.51h org 0h br sio_init org 01h br siojob sio_init: mov siodath, #0h mov siodatl, #0h clr1 irqsio ; clears interrupt request flag of sio set1 sioen ; enables sio initflg siots, siohiz, not siock1, not siock0 ; sets serial clock to external clock, starts receiving ; serial data, and sets p0d 1 /so pins to input port ; (output high impedance) ei ; permits all interrupts ; main processing main: call job call job br main siojob: get dbf, siosfr ; reads reception data mov rph, #0000b ; sets general register to low address 5h of bank0 mov rpl, #1010b ; bcd ? 0 ld siodath, dbf1 ; stores reception data on ram ld siodatl, dbf0 ; ei reti . . . .
chapter 14 interrupt functions the m pd17120 subseries has two internal interrupt functions and one external interrupt function. it can be used in various applications. the interrupt control circuit of this product has the features listed below. this circuit enables very high-speed interrupt handling. (a) used to determine whether an interrupt can be accepted with the interrupt mask enable flag (inte) and interrupt enable flag (ip ). (b) the interrupt request flag (irq ) can be tested or cleared. (interrupt generation can be checked by software). (c) standby mode (stop, halt) can be released by an interrupt request. (release source can be selected by the interrupt enable flag.) cautions 1. in interrupt handling, the bcd, cmp, cy, z, and ixe flags are saved in the stack automatically by the hardware for one level of multiple interrupts. the dbf and wr are not saved by the hardware when peripheral hardware such as the timers or serial interface is accessed in interrupt handling. it is recommended that the dbf and wr be saved in ram by the software at the beginning of interrupt handling. saved data can be loaded back into the dbf and wr immediately before the end of interrupt handling. 2. because the interrupt stack is only one level, multi-interrupt by hardware cannot be executed. if the interrupt over one level is accepted, the first data is lost. 145
chapter 14 interrupt functions 146 14.1 interrupt sources and vector address for every interrupt in the m pd17120 subseries, when the interrupt is accepted, a branch occurs to the vector address associated with the interrupt source. this method is called the vectored interrupt method. table 14-1 lists the interrupt sources and vector addresses. if two or more interrupt requests occur or the retained interrupt requests are enabled at the same time, they are handled according to priorities shown in table 14-1. table 14-1. interrupt source types vector internal/ address external int pin (rf: 0fh, bit 0) 1 0003h irq ip iegmd0, 1 external rising edge or falling rf: 3fh, rf: 2fh, rf: 1fh edge can be selected. bit 0 bit 0 timer 2 0002h irqtm iptm internal rf: 3eh, rf: 2fh, C bit 0 bit 1 sio 3 0001h irqsio ipsio internal rf: 3dh, rf: 2fh, C bit 0 bit 2 interrupt source priority irq flag ip flag ieg flag remarks
chapter 14 interrupt functions 147 14.2 hardware components of the interrupt control circuit the flags of the interrupt control circuit are explained below. 14.2.1 interrupt request flag (irq ) and the interrupt enable flag (ip ) the interrupt request flag (irq ) is set to 1 when an interrupt request occurs. when interrupt handling is executed, the flag is automatically cleared to 0. an interrupt enable flag (ip ) is provided for each interrupt request flag. if the flag is 1, an interrupt is enabled. if it is 0, the interrupt is disabled. 14.2.2 ei/di instruction the ei/di instruction is used to determine whether an accepted interrupt is to be executed. if the ei instruction is executed, inte for enabling interrupt reception is set. since the inte flag is not registered in the register file, flag status cannot be checked by instructions. the di instruction clears the inte flag to 0 and disables all interrupts. at reset the inte flag is cleared to 0 and all interrupts are disabled. table 14-2. interrupt request flag and interrupt enable flag interrupt interrupt request flag enagle flag irq set by edge detection of an int pin input signal. ip a detection edge is selected by iegmd0 or iegmd1. irqtm set by a match signal from timer. iptm irqsio set by a serial data transmission end signal from ipsio the serial interface. signal for setting the interrupt request flag
chapter 14 interrupt functions 148 figure 14-1. interrupt control register (1/4) rf: 0fh read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 0 0 bit 0 int note r read=r, write=w int 0 1 state of int pin int pin noise elimination circuit sets logical status to 0 during peek instruction execution. int pin noise elimination circuit sets logical status to 1 during peek instruction execution. note since the int flags are not latched, they change all the time in response to the logical state of the pin, however, once the irq flag is set, it stays set until an interrupt is accepted. the poke instruction to address 0fh is invalid. rf: 1fh read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 iegmd1 0 bit 0 iegmd0 0 r/w read=r, write=w iegmd1 iegmd0 0 0 1 1 0 1 0 1 selection of the interrupt detection edge of the int pin interrupt at the rising edge interrupt at the falling edge interrupt at both edges
chapter 14 interrupt functions 149 figure 14-1. interrupt control register (2/4) rf: 3fh read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 0 0 bit 0 irq 0 r/w read=r, write=w irq 0 1 int pin interrupt request (at reading) no interrupt request has been issued from the int pin or an int pin interrupt is being handled. an interrupt request from the int pin occurs or an int pin interrupt is being held. irq 0 1 int pin interrupt request (at writing) an interrupt request from the int pin is forcibly released. an interrupt request from the int pin is forced to occur. rf: 3fh read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 0 0 bit 0 irqtm 1 r/w read=r, write=w irqtm 0 tm interrupt request (at reading) 1 no interrupt request has been issued from timer or a timer interrupt is being handled. the contents of the timer count register matches that of the timer modulo register and an interrupt request occurs. or a timer interrupt request is being held. irqtm 0 tm interrupt request (at writing) 1 an interrupt request from timer is forcibly released. an interrupt request from timer is forced to occur. remark if tmres is set to 1, irqtm is cleared to 0. irqtm is cleared to 0 immediately after stop instruction is executed.
chapter 14 interrupt functions 150 figure 14-1. interrupt control register (3/4) rf: 3dh read/write initial value when reset bit 3 0 0 bit 2 0 0 bit 1 0 0 bit 0 irqsio 0 r/w read=r, write=w irqsio 0 1 sio interrupt request (at reding) no interrupt request has been issued from the serial interface or a serial interface interrupt is being handled. serial interrupt transmission is completed and an interrupt request occurs. or, a serial interface intrrupt request is being held. irqsio 0 sio interrupt request (at writing) an interrupt request from the serial interface is forcibly released. an interrupt request from the serial interface is forced to occur. 1
chapter 14 interrupt functions 151 figure 14-1. interrupt control register (4/4) rf: 2fh read/write initial value when reset bit 3 0 0 bit 2 ipsio 0 bit 1 iptm 0 bit 0 ip 0 r/w read=r, write=w ip 0 int pin interrupt enable disables an interrupt from the int pin. holds interrupt handling when the irq flag is set to 1. 1 enables an interrupt from the int pin. executes the ei instruction. if the irq flag is set to 1, executes interrupt handling. iptm 0 tm interrupt enable disables an interrupt from timer. holds an interrupt if the irqtm flag is set to 1. 1 enables an interrupt from timer. executed the ei instruction. if the irqtm flag is set to 1, executes interrupt handling. ipsio 0 sio interrupt enable disables an interrupt from serial interface. holds an interrupt if the irqsio flag is set to 1. 1 enables an interrupt from serial interface. executed the ei instruction. if the irqsio flag is set to 1, executes interrupt handling.
chapter 14 interrupt functions 152 14.3 interrupt sequence 14.3.1 acceptance of interrupts the moment an interrupt is accepted, the instruction cycle of the instruction which has been executed is terminated, and the interrupt operation is started thus altering the flow of the program to the vector address. however, if the interrupt occurs during execution of the movt instruction, the ei instruction or an instruction which has satisfied the skip condition, the processing of this interrupt is started after two instruction cycles are completed. if interrupt operation is started, one level of the address stack register is consumed to store the return address of the program, and also a level of the interrupt stack register is used to save the psword in the system register. if multiple interrupts are enabled and occure simultaneously, the interrupts are processed in order of higher priority. in this case, an interrupt with a lower priority is put on hold until the interrupts with higher priority are processed. for details of the priority levels, refer to table 14-1. types of interrupt factors . caution the psword is automatically reset to 00000b after being saved in the interrupt stack register.
chapter 14 interrupt functions 153 figure 14-2. interrupt handling procedure interrupt request generation set irq ip set? ei instruction executed? (inte=1?) no no yes yes clear inte flat and irq associated with accepted interrupt to 0 decrement stack pointer by 1 (sp-1) save contents of program counter in stack pointed to by stack pointer load vector address into program counter save psword content in interrupt stack register hold interrupt until ip is set hold interrupt until ei instruction is executed
chapter 14 interrupt functions 154 14.3.2 return from the interrupt routine execute the reti instruction to return from the interrupt handling routine. during the reti instruction cycle, processing in the figure below occurs. figure 14-3. return from interrupt handling execute reti instruction load contents of stack pointed to by stack pointer into program counter load contents of interrupt-dedicated stack register into psword increment stack pointer value by one cautions 1. the inte flag is not set for the reti instruction. interrupt handling is completed. to handle a pending interrupt successively, execute the ei instruction immediately before the reti instruction and set the inte flag to 1. 2. to execute the reti instruction following the ei instruction, no interrupt is accepted between ei instruction execution and reti instruction execution. this is because the ei instruction sets the inte flag to 1 after the execution of the subsequent instruction is completed. example ei instruction execution timer 0 interrupt generation timer 1 interrupt generation (held) timer 0 interrupt generation (held) reti timer 1 interrupt handling ei reti timer 0 interrupt handling single interrupt
chapter 14 interrupt functions 155 14.3.3 interrupt acceptance timing figure 14-4 shows the interrupt acceptance timing chart. the m pd17120 subseries executes an instruction with 16 clocks, which is one instruction cycle. one instruction cycle is subdivided into m0-m3 in terms of 4 clocks as a unit. the timing of the program recognizing the interrupt occurrence coincides with the edge preceding the m2. figure 14-4. interrupt acceptance timing chart (when inte=1 and ip =1) (1/3) <1> when an interrupt has occurred before m2 of an instruction other than movt or ei machine cycle instruction irq m0 an instruction other than movt or ei int cycle m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 vector address instruction interrupt occurrence recognized <2> when the skip condition for the skip instruction is materialized in <1> <3> when an interrupt has occurred after m2 of an instruction other than movt or ei machine cycle instruction irq m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 int cycle vector address instruction interrupt occurrence recognized an instruction other than movt or ei an instruction other than movt or ei machine cycle instruction irq m0 skip instruction handled as nop m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 int cycle interrupt occurrence recognized vector address instruction
chapter 14 interrupt functions 156 figure 14-4. interrupt acceptance timing chart (when inte=1, ip =1) (2/3) <4> when an interrupt has occurred before m2 of a movt instruction machine cycle instruction irq m0 movt instruction int cycle m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 vector address instruction interrupt occurrence recognized <5> when an interrupt has occurred before m2' of a movt instruction machine cycle instruction irq m0 movt instruction int cycle m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 vector address instruction interrupt occurrence recognized <6> when an interrupt has occurred before m2 of an ei instruction machine cycle instruction irq m0 ei instruction int cycle m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 vector address instruction interrupt occurrence recognized an instruction other than movt or ei <7> when an interrupt has occurred after m2 of an ei instruction machine cycle instruction irq m0 ei instruction int cycle m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 vector address instruction interrupt occurrence recognized an instruction other than movt or ei
chapter 14 interrupt functions 157 figure 14-4. interrupt acceptance timing chart (inte=1 and ip =1) (3/3) <8> when an interrupt has occurred during skipping (nop handling) by a skip instruction remarks 1. the int cycle is for preparing interrupts. during this cycle, pc and psword saving and irq clearing are performed. 2. for execution of the movt instruction, two instruction cycles are exceptionally required. 3. the ei instruction is considered to prevent multiple interrupts from occurring when returning from the interrupt operation. machine cycle instruction irq m0 skip instruction int cycle m1 m2 m3 m0 m1 m2 m3 m0 m1 m2 m3 m0 m1 vector address instruction interrupt occurrence recognized handled as nop
chapter 14 interrupt functions 158 14.4 program example of interrupt ? program example of contermeasure for noise reduction of external interrupt (int pin) this example assumes the case of assigning int pin for key input, etc. when taking into the microcontroller data in kind of switch such as key input processing, it takes some time for the level of input voltage to be stabilized after pushing the key or switch. accordingly, the countermeasures for removing the noise generated by key, etc. should be executed by software. in the following program, after generating external interrupt, the signal from int pin becomes effective after confirming that there is not change in the level of int pin two times in every 100 m s. example waitcnt mem 0.00h ; counter of wait processing keyon flg 0.01h.3 ; if key on is determined (even just once), keyon=1 second flg 0.01h.0 ; a flag describing key-checking for the second time. org 0h br job_init org 3h br int_job . . . . . job_init: mov waitcnt, #0 ; clears ram and the flag on ram clr2 keyon, second ; initflg not iegmd1, iegmd0 ; rising edge is effective for the interrupt from int pin clr1 irq set1 ip ei . . . . . main: call job ; arbitrary processing call job ; arbitrary processing . . . . . br main
chapter 14 interrupt functions 159 int_job: nop ; loop which executes waiting for 100 m s at 8 mhz nop ; 2 m s (1 instruction) 5 instructions 10 times ; (count value at wait) add waitcnt, #01 ; ske waitcnt, #0ah ; br int_job ; skf1 int ; check the level of int pin br key_off ; if int pin is high level, interrupt is invalid, and returns ; to main processing skf1 second ; first wait? br wait_end ; if it is the first time, wait again after setting second. ; in the case of the second time, finish wait processing set1 second ; mov waitcnt, #0 br int_job wait_end: set1 keyon ; judges that there is key input br int_job_end key_off: clr1 second ; second ? 0 int_job_end: mov waitcnt, #0 ei reti
[memo] 160
chapter 15 standby functions 15.1 outline of standby function the m pd17120 subseries reduces current consumption by using a standby function. in standby mode, the series uses stop mode or halt mode depending on the application. stop mode is a mode that stops the system clock. in this mode, the cpu's current consumption is mostly limited to the leakage current. therefore, this is useful for retaining the contents of the data memory without operating the cpu. halt mode is a mode that halts cpu operation because the clock supplying the cpu is stopped even when the system clock's oscillation continues. although, compared with stop mode, this mode does not reduce the current consumption, operation can start immediately after halt is canceled because the system clock is oscillating. also, in either the stop mode or halt mode, the status of items such as the data memory, registers, the output port's output latch, etc. immediately before being set to standby mode are retained (stop 0000b excluded). therefore, before placing the system in standby mode, please set the port's status in a way that the current consumption of the whole system is reduced. 161
chapter 15 standby functions 162 table 15-1. states during standby mode stop mode halt mode instruction to set stop instruction halt instruction clock oscillation circuit oscillation stopped oscillation continued operation cpu ? operation stopped statuses ram ? immediately-preceding status retained port ? immediately-preceding status retained note 1 tm ? operation stopped ? operable (the count value is reset to "0".) (the count up is also disabled.) sio ? operable only when an external ? operable clock has been selected for the shift clock note 1 comparator note 2 ? operation stopped note 1 ? operation stopped (the result after resumption of the operation is "undefined".) int ? operable notes 1. at the point where stop 0000b has been executed, the pin's status is placed in input port mode even when the pin is used with its dual function. 2. limited to m pd17132, 17133, 17p132, and 17p133. cautions 1. be sure to place a nop instruction immediately before the stop instruction or the halt instruction. 2. both the interrupt request flag and the interrupt enable flag are set and are not placed in standby mode if their interruption is specified in the condition for canceling the standby mode.
chapter 15 standby functions 163 15.2 halt mode 15.2.1 halt mode setting the system is placed in halt mode by executing the halt instruction. the halt instruction's operands b 3 b 2 b 1 b 0 are the conditions for canceling halt mode. table 15-2. halt mode cancellation condition format: halt b 3 b 2 b 1 b 0 b bit condition for canceling halt mode note 1 b 3 at 1, cancellation by irq is enabled. notes 2, 4 b 2 "fixed to 0" b 1 at 1, forced cancellation by irqtm is enabled. note 3, 4 b 0 "fixed to 0" notes 1. at halt 0000b, only the resets (reset input; power-on/power-down reset) are valid. 2. it is required that ip =1. 3. regardless of the pitm's state, halt mode is canceled. 4. even if the halt instruction is executed when irq =1, the halt instruction is ignored (handled as the nop instruction) thus failing to place the system in halt mode. 15.2.2 start address after halt mode is canceled the start address varies depending on the cancellation condition and the interrupt enable condition. table 15-3. start address after halt mode cancellation cancellation condition start address after cancellation reset note 1 address 0 irq note 2 if di, the start address is the one following the halt instruction if ei, the start address is the interrupt vector. (if more than one irq have been set, the start address is the interrupt vector with a higher priority.) notes 1. valid resets include the reset input and power-on/power-down resets. 2. except for forced cancellation by irqtm, it is required that ip =1.
chapter 15 standby functions 164 figure 15-1. cancellation of halt mode (a) halt cancellation by reset input (b) halt cancellation by irq (if di) execution of the halt instruction irq operation mode halt mode operation mode (c) halt cancellation by irq (if ei) execution of the halt instruction interrupt operation acceptance irq operation mode halt mode operation mode execution of the halt instruction tm count up reset operation mode halt mode system reset srtate wait a operation mode (start of address 0) wait a: this refers to the wait time until tm counts the divide-by-256 clock up to 256. 256 256/f x (when approximately 32 ms and f x =2mhz)
chapter 15 standby functions 165 15.2.3 halt setting condition (1) forced cancellation by irqtm ? the timer is in the operable state (tmen=1) ? the timer's interrupt request flag is cleared (irqtm=0). (2) cancellation by the interrupt request flag (irq ) ? setting in a way that places beforehand the peripheral hardware used for halt cancellation in an operable state. timer operable state (tmen=1) serial interface serial interface circuit placed in operable state (siots=1, sioen=1) int pin setting the edge selection ? the interrupt request flag (irq ) of the peripheral hardware used for halt cancellation is cleared (to 0). ? the interrupt enable flag (ip ) of the peripheral hardware used for halt cancellation is set (to 1). caution be sure to code a nop instruction immediately before the halt instruction. the time of one instruction is generated between the irq operation instruction and the halt instruction by coding the nop instruction immediately before the halt instruction. therefore, in the case of the clr1 irq instruction, for example, the clearance of the irq is correctly reflected in the halt instruction (example 1). if a nop instruction is not coded immediately before the halt instruction, the clr1 irq instruction is not reflected in the halt instruction thus failing to place the system in halt mode (example 2).
chapter 15 standby functions 166 example 1. a correct program example . . . . . . (setting of irq ) . . . . . . clr1 irq nop ; codes a nop instruction immediately before the halt instruction ; (clearance of irq is reflected correctly to the halt instruction. halt 1000b ; executes the halt instruction correctly (placing the system in halt mode). . . . . . . . . . . . . 2. an incorrect program example . . . . . . (setting of irq ) . . . . . . clr1 irq ; clearance of irq is not reflected as to the halt instruction. ; (it is the instruction following the halt instruction that is reflected.) halt 1000b ; the halt instruction is ignored (not placing the system in halt mode.) . . . . . . . . . . . .
chapter 15 standby functions 167 15.3 stop mode 15.3.1 stop mode setting executing the stop instruction places the system in stop mode. operand b 3 b 2 b 1 b 0 of the stop instruction is the condition for canceling stop mode. table 15-4. stop mode cancellation condition format: stop b 3 b 2 b 1 b 0 b bit stop mode cancellation condition note 1 b 3 at 1, this bit enables cancellation by irq . note 2, 3 b 2 "fixed to 0" b 1 "fixed to 0" b 0 "fixed to 0" notes 1. at stop 0000b, only the resets (reset input; power-on/power-down reset) are valid. the microcontroller is internally initialized to the state immediately following the resetting when stop 0000b is executed. 2. it is required that ip =1. cancellation by irqtm is not possible. 3. even if the stop instruction is executed when irq =1, the stop instruction is ignored (handled as a nop instruction) thus failing to place the system in stop mode. 15.3.2 start address after stop mode cancellation the start address varies depending on the cancellation condition and the interrupt enable condition. table 15-5. start address after stop mode cancellation cancellation condition start address after cancellation reset note 1 address 0 irq note 2 if di, the start address is the one following the stop instruction if ei, the start address is the interrupt vector. (if more than one irq have been set, the start address is the interrupt vector with highest priority.) notes 1. valid resets include the reset input and power-on/power-down resets. 2. it is required that ip =1. cancellation by irqtm is not possible.
chapter 15 standby functions 168 figure 15-2. cancellation of stop mode (a) stop cancellation by reset input (b) stop cancellation by irq (if di) (c) stop cancellation by irq (if ei) execution of the stop instruction tm count up reset operation mode stop mode system reset state wait b operation mode (start of address 0) wait b: this refers to the wait time until tm counts the divide-by-256 clock up to 256. 256 256/f x + a (when approximately 32 ms+ a and f x =2mhz) a : oscillation growth time (varies depending on the resonator) execution of the stop instruction tm count up ipq operation mode stop mode wait c operation mode wait c: this refers to the wait time until tm counts the divide-by-m clock up to (n+1). (n+1) m/f x + a (n and m: values immediately before the system is placed in stop mode) a : oscillation growth time (varies depending on the resonator) execution of the stop instruction interrupt operation acceptance, tm count up ipq operation mode stop mode wait c operation mode wait c: this refers to the wait time until tm counts the divide-by-m clock up to (n+1). (n+1) m/f x + a (n and m: values immediately before the system is placed in stop mode) a : oscillation growth time (varies depending on the resonator)
chapter 15 standby functions 169 15.3.3 stop setting condition cancellation by irq cancellation by irq ? sets the edge selection (iegmd1, iegmd0) for the signal that is input from the int pin. ? sets the modulo register value of the timer (wait time for generation of oscillation stability). ? clears the interrupt request flag (irq) of the int pin (to 0). ? sets the interrupt enable flag (ip) of the int pin (to 1.) cancellation by irqsio ? sets the source clock to the external clock (siock1=0, siock0=0) that is input from the sck pin. ? sets the serial interface to the operable state (siots=1). ? sets the modulo register value of the timer (wait time for generation of oscillation stability). ? clears the interrupt request flag (irqsio) of the serial interface (to 0). ? sets the interrupt enable flag (ipsio) of the serial interface (to 1). caution be sure to code a nop instruction immediately before the stop instruction. the time of one instruction is generated between the irq operation instruction and the stop instruction by coding the nop instruction immediately before the stop instruction. therefore, in the case of the clr1 irq instruction, for example, the clearance of irq is correctly reflected in the stop instruction (example 1). if a nop instruction is not coded immediately before the stop instruction, the clr1 irq instruction is not reflected in the stop instruction thus failing to place the system in stop mode (example 2).
chapter 15 standby functions 170 example 1. a correct program example . . . . . . (setting of irq ) . . . . . . clr1 irq nop ; codes a nop instruction immediately before the stop instruction. ; (clearance of irq is reflected correctly to the stop instruction. stop 1000b ; executes the stop instruction correctly (placing the system in stop mode). . . . . . . . . . . . . 2. an incorrect program example . . . . . . (setting of irq ) . . . . . . clr1 irq ; clearance of irq is not reflected to the stop instruction. ; (it is the instruction following the stop instruction that is reflected.) stop 1000b ; the stop instruction is ignored (not placing the system in stop mode.) . . . . . . . . . . . .
chapter 16 reset the following 3 types of resets are provided in the m pd17120 series. <1> reset by input to reset. <2> the power-on/power-down reset function when power is turned on or supply voltage drops. <3> the address stack overflow/underflow reset function. 16.1 reset functions the reset functions are used to initialize device operations. the state to be initialized depends on the type of reset. table 16-1. state of each hardware unit when reset reset type ? reset input during ? reset input during operation standby mode ? stack overflow or ? built-in power-on/power- ? built-in power-on/power- underflow down reset during down reset during hardware operation standby mode program counter 0000h 0000h 0000h port input/output mode input input input output latch 0 0 undefined general-purpose other than dbf undefined retains the status immedi- undefined data memory ately preceding the resetting. dbf undefined undefined undefined system register other than wr 0 0 0 wr undefined retains the status immedi- undefined ately preceding the resetting. control register sp=5h; irqtm1=1; tmen=1; cmpvref23=1 note ; sp=5h; int retains the cmprslt=1 note ; int retains the status of the int pin at status of the int pin at the the time; all the others go to 0. time; all the others go to 0. refer to 19.2 reserved symbols . timer count register 00h 00h undefined modulo register ffh ffh ffh serial interface's shift register undefined retains the status immedi- undefined (siosfr) ately preceding the resetting. note m pd17132, 17133, 17p132, and 17p133 only. 171
chapter 16 reset 172 figure 16-1. reset block configuration note the m pd17p132 and 17p133 have no pull-up resistor by mask option, and are always open. 16.2 resetting operation when reset is caused by the reset input is shown in the figure below. if the reset pin is set from low to high, system clock generation starts and an oscillation stabilization wait occurs with the timer. program execution starts from address 0000h. if power-on reset function is used, the reset signals shown in figure 16-2 are internally generated. operation is the same as that when reset is caused externally by the reset input. at address stack overflow and underflow reset, oscillation stabilization wait time (wait a) does not occur. operation starts from address 0000h after initial statuses are internally set. figure 16-2. resetting reset tmen tmres operationg mode reset wait a note operating mode note this is oscillation stabilization wait time. operating mode is set when timer counts system clocks 256 256 time (approx. 8ms, at f x =8 mhz/approx. 32 ms, at f cc =2 mhz) internal bus rf : 10h 0 0 0 pdresen v dd clear signal mask option note low-voltage detection circuit power-on reset circuit internal reset signal oscillation disabled reset
chapter 16 reset 173 16.3 power-on/power-down reset function the m pd17120 subseries is provided with two reset functions to prevent malfunctions from occurring in the microcontroller. they are the power-on reset function and power-down reset function. the power-on reset function resets the microcontroller when it detects that power was turned on. the power-down reset function resets the microcontroller when it detects drops in the power voltage. these functions are implemented by the power-voltage monitoring circuit whose operating voltage has a different range from the logic circuits in the microcontroller and the oscillation circuit (which stops oscillation at reset to put the microcontroller in a temporary stop state). conditions required to enable these functions and their operations will be described next. caution when designing an applied circuit requiring a high level of reliability, make sure that its resetting relies on the built-in power-on/power-down reset function only. also, design the circuit in such a way that the reset signal is input externally. 16.3.1 conditions required to enable the power-on reset function this function is effective when used together with the power-down reset function. the following conditions are required to validate the power-on reset function: <1> the power voltage must be 4.5 to 5.5 v during normal operation, including the standby state. <2> the frequency of the system clock oscillator must be 400 khz to 4 mhz. note <3> the power-down reset function must be enabled during normal operation, including the standby state. <4> the power voltage must rise from 0 v to the specified voltage. <5> the time it takes for the power voltage to rise from 0 to 2.7 v must be shorter than the oscillation stabilization wait time counted in timer of the m pd17120 subseries. (system clock 256 256 counts: approx. 16 ms, at f x =4 mhz/approx. 32 ms, at f cc =2 mhz) note m pd17121/17133/17p133 only cautions 1. if the above conditions are not satisfied, the power-on reset function will not operate effectively. in this case, an external reset circuit needs to be added. 2. in the standby state, even if the power-down reset function operates normally, general- purpose data memory (except for dbf) retains data up to v dd =2.7 v. if, however, data is changed due to an external error, the data in memory is not guaranteed.
chapter 16 reset 174 16.3.2 description and operation of the power-on reset function the power-on reset function resets the microcontroller when it detects that power was turned on in the hardware, regardless of the software state. the power-on reset circuit operates under a lower voltage than the other internal circuits in the m pd17120 subseries. it initializes the microcontroller regardless whether the oscillation circuit is operating. when the reset operation is terminated, timer counts the number of oscillation pulses sent from the oscillator until it reaches the specified value. within this period, oscillation becomes stable and the power voltage applied to the microcontroller enters the range (v dd =2.7 to 5.5 v at 400 khz to 4 mhz note ) in which the microcontroller is guaranteed to operate. when this period elapses, the microcontroller enters normal operation mode. figure 16-3 shows an example of the power-on reset operation. note m pd17121/17133/17p133 only operation of the power-on reset circuit <1> this circuit always monitors the voltage applied to the v dd pin. <2> this circuit resets the microcontroller note until power reaches a particular voltage (typically 1.5 v), regardless whether the oscillation circuit is operating. <3> this circuit stops oscillation during the reset operation. <4> when reset is terminated, timer counts oscillation pulses. the microcontroller waits until oscillation becomes stable and the power voltage becomes v dd =2.7 v or higher. note it is from the point when the supply voltage has reached a level allowing the internal circuit to be operable (accepting the internal reset signal) that the resetting takes effect within the microcontroller.
chapter 16 reset 175 figure 16-3. example of the power-on reset operation notes 1. during the operation-undefined period, certain operations on the m pd17120 subseries are not guaranteed. however, the power-on reset function is guaranteed in this period. 2. the operation-guaranteed period refers to the time in which all the operations specified for the m pd17120 subseries are guaranteed. 3. an operation stop state refers to the state in which all of the functions of the microcontroller are stopped. a : voltage at which oscillation starts b : voltage at which the power-on reset operation terminates v dd (v) 5.0 2.7 a b 0 time (t) state of oscillation period in which the microcon- troller is guar- anteed to operate power-on reset signal operation state of the micro- controller oscillation stop oscillation start undefined period note1 operation stop note 3 oscillating timer finishes counting guaranteed period note 2 operating mode power-on reset termination waiting until oscillation becomes stable v dd gnd reset pd17120 subseries m
chapter 16 reset 176 16.3.3 condition required for use of the power-down reset function the power-down reset function can be enabled or disabled using software. the following conditions are required to use this function: ? the power voltage must be 4.5 to 5.5 v during normal operation, including the standby state. ? the frequency of the system clock oscillator must be 400 khz to 4 mhz. note note m pd17121/17133/17p133 only caution when the microcontroller is used with a power voltage of 2.7 to 4.5 v, add an external reset circuit instead of using the internal power-down reset circuit. if the internal power-down reset circuit is used with a power voltage of 2.7 to 4.5 v, reset operation may not terminate. 16.3.4 description and operation of the power-down reset function this function is enabled by setting the power-down reset enable flag (pdresen) using software. when this function detects a power voltage drop, it issues the reset signal to the microcontroller. it then initializes the microcontroller. stopping oscillation during reset prevents the power voltage in the microcontroller from fluctuating out of control. when the specified power voltage recovers and the power-down reset operation is terminated, the microcontroller waits the time required for stable oscillation using the timer. the microcontroller then enters normal operation (starts from the top of memory). figure 16-4 shows an example of the power-down operation. figure 16-5 shows an example of reset operation during the period from power-down reset to power recovery. operation of the power-down reset circuit <1> this circuit always monitors the voltage applied to the v dd pin. <2> when this circuit detects a power voltage drop, it issues a reset signal to the other parts of the microcontroller. it continues to send this reset signal until the power voltage recovers or all the functions in the microcontroller stop. <3> this circuit stops oscillation during the reset operation to prevent software crashes. when the power voltage recovers to the low-voltage detection level (typically 3.5 v, 4.5 v maximum) before the power-down reset function stops, the microcontroller waits the time required for stable oscillation using timer, then enters normal operation mode. <4> when the power voltage recovers from 0 v, the power-on reset function has priority. <5> after the power-down reset function stops and the power voltage recovers before it reaches 0 v, the microcontroller waits using timer until oscillation becomes stable and the power voltage (v dd ) reaches 2.7 v. the microcontroller then enters normal operation mode.
chapter 16 reset 177 figure 16-4. example of the power-down reset operation note the undefined operation area refers to the area in which operation specified for the m pd17120 subseries is not assured. however, even in this area, the power-down reset function operates, thus continuing to generate resets until all the other functions within the microcontroller are stopped. v dd (v) 5.0 4.5 2.7 c state of oscillation period in which the microcon- troller is guar- anteed to operate power-down reset signal operation state of the micro- controller 3.5 0 oscillating guaranteed period power-on reset signal oscillating mode reset state power-down reset oscillation stop undefined period note time (t) maximum voltage detected by the power-down reset function: 4.5v typical voltage detected by the power-down reset function: 3.5v voltage at which the power-down reset function terminates= power-on reset voltage (b): c v dd gnd reset pd17120 subseries m
chapter 16 reset 178 figure 16-5. example of reset operation during the period from power-down reset to power recovery note the undefined operation area refers to the area in which operation specified for the m pd17120 subseries is not assured. however, even in this area, the power-down reset function operates, thus continuing to generate resets until all the other functions within the microcontroller are stopped. v dd (v) 5.0 4.5 2.7 c state of oscillation period in which the microcon- troller is guar- anteed to operate power-down reset signal operation state of the micro- controller 3.5 0 oscillating power-on reset signal oscillating mode reset state power-down reset time (t) maximum voltage detected by the power-down reset function: 4.5v typical voltage detected by the power-down reset function: 3.5v voltage at which the power-down reset function terminates= power-on reset voltage (b): c v dd gnd reset pd17120 subseries m oscillation stop undefined period note oscillating guaranteed period timer finishes counting operating mode waiting until oscillation becomes stable guaranteed period
chapter 17 one-time prom writing/verifying the on-chip program memory of the m pd17p132 and 17p133 is a 1024 16-bit one-time prom. pins listed in table 17-1 are used for one-time prom writing/verifying. the address is updated by the clock signal input from the clk pin. caution int/v pp pin is used as v pp pin in program writing/verifying mode. therefore, there is a possibility of overrunning of the microcontroller when voltage higher than v dd + 0.3 v is applied to int/ v pp pin in normal operation mode. pay careful attention to esd protection. table 17-1. pins used for writing/verifying program memory pin function v pp applies program voltage. apply 12.5 v to this pin. v dd power supply pin. apply 6 v to this pin. clk clock input for updating address. updates program memory address by inputting four pulses. md 0 -md 3 select operation mode. d 0 -d 7 8-bit data i/o pins. 17.1 differences between mask rom version and one-time prom version the m pd17p132 and 17p133 are microcontrollers replacing the program memory of the on-chip mask rom version m pd17132 and 17133 to one-time prom. table 17-2 shows the differences between mask rom version and one- time prom version. differences between each products are only its capacity of rom/ram, and whether it can specify mask option or not. the cpu function and internal peripheral hardware of each product (excluding comparator) are the same. therefore, at system designing, the m pd17p132 can be used for evaluating program of the m pd17120/17132 . also, the m pd17p133 can be used for evaluating the m pd17121/17133 in the same way. 179
chapter 17 one-time prom writing/verifying 180 table 17-2. differences between mask rom version and one-time prom version item m pd17120 m pd17132 m pd17p132 m pd17121 m pd17133 m pd17p133 rom mask rom one-time prom mask rom one-time prom 768 16 bit 1024 16 bit 768 16 bit 1024 16 bit (0000h-02ffh) (0000h-03ffh) (0000h-02ffh) (0000h-03ffh) ram 64 4 bit 111 4 bit 64 4 bit 111 4 bit p0d and p0e pins and pull- mask option not available mask option not available up resistor of reset pin v pp pin, operating mode not available available not available available selection pin operating frequency f cc =400 khz to 2.4 mhz f x =400 khz to 4 mhz (v dd =2.7 to 5.5 v) f x =400 khz to 8 mhz (v dd =4.5 to 5.5 v) comparator not available available not available available caution although, functionally, the prom product is highly compatible with the masked rom product, they still differ from each other in terms of their internal rom circuits and some electrical features. when switching from a prom product to a rom product, ensure to make sufficient application evaluations based on masked-rom product samples. 17.2 operating mode in program memory writing/verifying the m pd17p132 and 17p133 become program memory writing/verifying mode by applying +6v to v dd pin and +12.5 v to v pp pin after reset state for a fixed time (v dd =5 v, reset=0 v). this mode becomes the following operating mode by the setting of pins md 0 to md 3 . regarding pins other than those shown in table 17-1, connect them all individually to the gnd through pull-down resistors. for details, refer to 1.4 (2) . table 17-3. operating mode setting operating mode setting v pp v dd md 0 md 1 md 2 md 3 h l h l clear program memory address to 0. l h h h write mode l l h h verify mode remark : don't care (l or h) operating mode +12.5 v +6 v h h h program inhibit mode
chapter 17 one-time prom writing/verifying 181 17.3 writing procedure of program memory the program memory can be written at high speeds in the following procedure. (1) pull down the unused pins to gnd. (x out pin is open.) mask the clk pin low. (2) apply 5 v to the v dd pin. make v pp pin low. (3) wait for 10 m s. then, apply 5 v to v pp pin. (4) set the program memory address 0 clear mode using mode selector pins. (5) apply 6 v to v dd and 12.5 v to v pp . (6) set the program inhibit mode. (7) write data in mode for 1 ms writing. (8) set the program inhibit mode. (9) set the verify mode (md 0 -md 3 =llhh). if the program has been correctly written, proceed to (10). if not, repeat (7) through (9). (10) additional writing of (number of times ( ) the program has been written in (7) through (9)) 1ms. (11) set the program inhibit mode. (12) input four pulses to the clk pin to update the program memory address by one. (13) repeat (7) through (12) until the last address in programmed. (14) set the program memory address 0 clear mode. (15) change the voltage of v dd and v pp pins to 5 v. (16) turn off the power. figure 17-1 shows the procedures of (2) through (12).
chapter 17 one-time prom writing/verifying 182 figure 17-1. procedure of program memory writing 17.4 reading procedure of program memory (1) pull down the unused pins to gnd. (x out pin is open.) make the clk pin low. (2) apply 5 v to the v dd pin. make v pp pin low. (3) wait for 10 m s. then, apply 5 v to v pp pin. (4) set the program memory address 0 clear mode using mode selector pins. (5) apply 6 v to v dd and 12.5 v to v pp . (6) set mode selector pins to the program inhibit mode. (7) set the verify mode. when clock pulses are input to the clk pin, data for each address can be sequentially output with four clocks as one cycle. (8) set the program inhibit mode. (9) set the program memory address 0 clear mode. (10) change the voltage of v dd and v pp pins to 5 v. (11) turn off the power. repeat times write verify additional writing address increment reset v dd +1 v dd gnd v dd v pp v dd gnd v pp clk d 0 d 7 md 0 md 1 md 2 md 3 hi-z input data output data input data hi-z hi-z hi-z
chapter 17 one-time prom writing/verifying 183 figure 17-2 shows the program reading procedure (2) through (9). figure 17-2. procedure of program memory reading reset v dd +1 v dd gnd v dd v pp v dd gnd v pp clk md 0 md 1 d 0 d 7 hi-z output data output data hi-z md 2 md 3 "l"
[memo] 184
chapter 18 instruction set 18.1 overview of the instruction set b 15 b 14 -b 11 0 1 bin hex 0000 0 add r, m add m, #n4 0001 1 sub r, m sub m, #n4 0010 2 addc r, m addc m, #n4 0011 3 subc r, m subc m, #n4 0100 4 and r, m and m, #n4 0101 5 xor r, m xor m, #n4 0110 6 or r, m or m, #n4 inc ar inc ix movt dbf, @ar br @ar call @ar ret retsk ei di 0111 7 reti push ar pop ar get dbf, p put p, dbf peek wr, rf poke rf, wr rorc r stop s halt h nop 1000 8 ld r, m st m, r 1001 9 ske m, #n4 skge m, #n4 1010 a mov @r, m mov m, @r 1011 b skne m, #n4 sklt m, #n4 1100 c br addr call addr 1101 d mov m, #n4 1110 e skt m, #n 1111 f skf m, #n 185
chapter 18 instruction set 186 18.2 legend ar : address register asr : address stack register indicated by stack pointer addr : program memory address (11 bits, the most-significant bit is fixed to 0) bank : bank register cmp : compare flag cy : carry flag dbf : data buffer h : halt release condition intef : interrupt enable flag intr : register saved automatically to stack when interrupt occurs intsk : interrupt stack register ix : index register mp : data memory row address pointer mpe : memory pointer enable flag m : data memory address indicated by m r and m c m r : data memory row address (upper) m c : data memory column address (lower) n : bit position (4 bits) n4 : immediate data (4 bits) pc : program counter p : peripheral address p h : peripheral address (upper 3 bits) p l : peripheral address (lower 4 bits) r : general register column address rf : register file address rf r : register file row address (upper 3 bits) rf c : register file column address (lower 4 bits) sp : stack pointer s : stop release condition wr : window register ( ) : contents addressed by
chapter 18 instruction set 187 18.3 list of the instruction set group mnemonic operand operation add add r, m (r) ? (r) + (m) 00000 m r m c r m, #n4 (m) ? (m) + n4 10000 m r m c n4 addc r, m (r) ? (r) + (m) + cy 00010 m r m c r m, #n4 (m) ? (m) + n4 + cy 10010 m r m c n4 inc ar ar ? ar + 1 00111 000 1001 0000 ix ix ? ix + 1 00111 000 1000 0000 subtract sub r, m (r) ? (r) C (m) 00001 m r m c r m, #n4 (m) ? (m) C n4 10001 m r m c n4 subc r, m (r) ? (r) C (m) Ccy 00011 m r m c r m, #n4 (m) ? (m) C n4 Ccy 10011 m r m c n4 logical or r, m (r) ? (r) (m) 00110 m r m c r operation m, #n4 (m) ? (m) n4 10110 m r m c n4 and r, m (r) ? (r) (m) 00100 m r m c r m, #n4 (m) ? (m) n4 10100 m r m c n4 xor r, m (r) ? (r) (m) 00101 m r m c r m, #n4 (m) ? (m) n4 10101 m r m c n4 test skt m, #n cmp ? 0, if (m) n=n, then skip 11110 m r m c n skf m, #n cmp ? 0, if (m) n=0, then skip 11111 m r m c n compare ske m, #n4 (m) Cn4, skip if zero 01001 m r m c n4 skne m, #n4 (m) Cn4, skip if not zero 01011 m r m c n4 skge m, #n4 (m) Cn4, skip if not borrow 11001 m r m c n4 sklt m, #n4 (m) Cn4, skip if borrow 11011 m r m c n4 rotate rorc r cy ? (r) b3 ? (r) b2 ? (r) b1 ? (r) b0 00111 000 0111 r transfer ld r, m (r) ? (m) 01000 m r m c r st m, r (m) ? (r) 11000 m r m c r mov @r, m if mpe = 1: (mp, (r)) ? (m) 01010 m r m c r if mpe = 0: (bank, m r , (r)) ? (m) m, @r if mpe = 1: (m) ? (mp, (r)) 11010 m r m c r if mpe = 0: (m) ? (bank, m r , (r)) m, #n4 (m) ? n4 11101 m r m c n4 movt note dbf, @ar sp ? spC1, asr ? pc, pc ? ar, 00111 000 0001 0000 dbf ? (pc), pc ? asr, sp ? sp+1 note as an exception, execution of movt instruction requires two instruction cycles. machine code op code operand
chapter 18 instruction set 188 group mnemonic operand operation transfer push ar sp ? sp C 1, asr ? ar 00111 000 1101 0000 pop ar ar ? asr, sp ? sp + 1 00111 000 1100 0000 peek wr, rf wr ? (rf) 00111 rf r 0011 rf c poke rf, wr (rf) ? wr 00111 rf r 0010 rf c get dbf, p dbf ? (p) 00111 p h 1011 p l put p, dbf (p) ? dbf 00111 p h 1010 p l branch br addr pc ? addr 01100 addr @ar pc ? ar 00111 000 0100 0000 sub- call addr sp ? sp C 1, asr ? pc, 11100 addr routine pc ? addr @ar sp ? sp C 1, asr ? pc, 00111 000 0101 0000 pc ? ar ret pc ? asr, sp ? sp+1 00111 000 1110 0000 retsk pc ? asr, sp ? sp+1 and skip 00111 001 1110 0000 reti pc ? asr, intr ? intsk, sp ? sp+1 00111 100 1110 0000 interrupt ei intef ? 1 00111 000 1111 0000 di intef ? 0 00111 001 1111 0000 others stop s stop 00111 010 1111 s halt h halt 00111 011 1111 h nop no operation 00111 100 1111 0000 18.4 assembler (as17k) macro instructions legend flag n : flg symbol < > : can be omitted mnemonic operand operation n macro sktn flag 1, flag n if (flag 1) ~ (flag n)=all "1" then skip 1 n 4 instructions skfn flag 1, flag n if (flag 1) ~ (flag n)=all "0", then skip 1 n 4 setn flag 1, flag n (flag 1) ~ (flag n) ? 1 1 n 4 clrn flag 1, flag n (flag 1) ~ (flag n) ? 0 1 n 4 notn flag 1, flag n if (flag n)="0", then (flag n) ? 11 n 4 if (flag n)="1", then (flag n) ? 0 initflg flag 1, if description=not flag n, then (flag n) ? 01 n 4 < flag n> if description=flag n, then (flag n) ? 1 bankn (bank) ? n n=0 machine code op code operand
chapter 18 instruction set 189 18.5 instructions 18.5.1 addition instructions (1) add r, m add data memory to general register <1> op code 10 87 43 0 00000 m r m c r <2> function when cmp=0, (r) ? (r) + (m) adds the data memory contents to the general register contents, and stores the result in general register. when cmp=1, (r) + (m) the result is not stored in the register. carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a carry occurs as a result of the addition. resets the carry flag cy, if no carry occurs. if the addition result is other than zero, zero flag z is reset, regardless of compare flag cmp.
chapter 18 instruction set 190 if the addition result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the addition result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. addition can be executed in binary 4-bit or bcd. the bcd flag for the psword specifies which kind of addition is to be executed. <3> example 1 adds the address 0.2fh contents to the address 0.03h contents, when row address 0 (0.00h-0.0fh) in bank 0 is specified as the general register (rph=0, rpl=0), and stores the result in address 0.03h: (0.03h) ? (0.03h) + (0.2fh) mem003 mem 0.03h mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 add mem003, mem02f example 2 adds the address 0.2fh contents to the address 0.23h contents, when row address 2 (0.20h-0.2fh) in bank 0 is specified as the general register (rph=0, rpl=4), and stores the result in address 0.23h: (0.23h) ? (0.23h) + (0.2fh) mem023 mem 0.23h mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 note mov rpl, #04h ; general register row address 2 add mem023, mem02f rp rph rpl register bit data note b 3 0 b 2 0 b 1 0 b 0 0 b 3 b 2 b 1 b 0 bank row address b c d
chapter 18 instruction set 191 rp (general register pointer) is assigned in the system register, as shown above. therefore, to set bank 0 and row address 2 in a general register, 00h must be stored in rph and 04h, in rpl. in this case, the subsequent arithmetic operation is executed in binary 4-bit operation, because the bcd flag is reset. example 3 adds the address 0.6fh contents to the address 0.03h contents and stores the result in address 0.03h. at this time, data memory address 0.6fh can be specified, by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=4, and ixl=0, i.e., ix=0.40h. (0.03h) ? (0.03h) + (0.6fh) address obtained as result of oring index register con- tents, 0.40h, and data memory address 0.2fh mem003 mem 0.03h mem02f mem 0.2fh mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00001000000b mov ixm, #04h ; mov ixl, #00h ; set1 ixe ; ixe flag ? 1 add mem003, mem02f ; ix 00001000000b (0.40h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00001101111b (0.6fh) example 4 adds the address 0.3fh contents to the address 0.03h contents and stores the result in address 0.03h. at this time, data memory address 0.3fh can be specified by specifying data memory address 2fh, if ixe=1, ixh=0, ixm=1, and ixl=0, i.e., ix=0.10h. (0.03h) ? (0.03h) + (0.3fh) address obtained as result of oring index register contents, 0.10h, and data memory address 0.2fh mem003 mem 0.03h mem02f mem 0.2fh
chapter 18 instruction set 192 mov bank, #00h mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00000010000b (0.10h) note mov ixm, #01h mov ixl, #00h set1 ixe ; ixe flag ? 1 add mem003, mem02f ; ix 00000010000b (0.10h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00100111111b (0.3fh) ix (index register) is assigned in the system register, as shown above. therefore, to specify ix=0.10h, 00h must be stored in ixh. 01h in ixm, and 00h in ixl. in this case, mp (memory pointer) for general register indirect transfer is invalid, because the mpe flag (memory pointer enable) is reset. <4> note the first operand for the add r, m instruction is a column address in general register. therefore, if the instruction is described as follows, the column address for the general register is 03h. mem013 mem 0.13h mem02f mem 0.2fh add mem013, mem02f indicates the general register column address. the lower 4 bits (in this case, 03h) are valid when cmp flag=1, the addition result is not stored. when bcd flag=1, the bcd result is stored. ix ixh ixm register bit data note b 3 p b 2 0 b 1 0 b 0 0 b 3 b 2 b 1 b 0 bank row address ixl b 3 b 2 b 1 b 0 m e 0 column address
chapter 18 instruction set 193 (2) add m, #n4 add immediate data to data memory <1> op code 10 87 43 0 10000 m r m c n4 <2> function when cmp=0, (m) ? (m) + n4 adds immediate data to the data memory contents, and stores the result in data memory. when cmp=1, (m) + n4 the result is not stored in the data memory. carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a carry occurs as a result of the addition; resets the carry flag cy if no carry occurs. if the addition result is other than zero, zero flag z is reset, regardless of compare flag cmp. if the addition result is zero with the compare flag reset (cmp=0), the zero flag z is set. if the addition result is zero with the compare flag set (cmp=1), the zero flag z is not changed. addition can be executed in binary 4-bit or bcd. the bcd flag for the psword specifies which kind of addition is to be executed. <3> example 1 adds 5 to the address 0.2fh contents, and stores the result in address 0.2fh: (0.2fh) ? (0.2fh) + 5 mem02f mem 0.2fh add mem02f, #05h example 2 adds 5 to the address 0.6fh contents and stores the result in address 0.6fh. at this time, data memory address 0.6fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=4, and ixl=0, i.e., ix=0.40h.
chapter 18 instruction set 194 (0.6fh) ? (0.6fh) + 05h address obtained as result of oring index register contents, 0.40h, and data memory address 0.2fh mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h mov ixl, #00h ; set1 ixe ; ixe flag ? 1 add mem02f, #05h ; ix 00001000000b (0.40h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00001101111b (0.6fh) example 3 adds 5 to the address 0.2fh contents and stores the result in address 0.2fh. at this time, data memory address 0.2fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=0, and ixl=0, i.e., ix=0.00h. (2.2fh) ? (0.2fh) + 05h address obtained as result of oring index register contents, 0.00h, and data memory address 0.2fh mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov ixh, #00h ; ix ? 00000000000b mov ixm, #00h mov ixl, #00h ; set1 ixe ; ixe flag ? 1 add mem02f, #05h ; ix 00000000000b (0.00h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00000101111b (0.2fh) <4> note when the cmp flag=1, the addition result is not stored. when the bcd flag=1, the bcd result is stored.
chapter 18 instruction set 195 (3) addc r, m add data memory to general register with carry flag <1> op code 10 87 43 0 00010 m r m c r <2> function when cmp=0, (r) ? (r) + (m) +cy adds the data memory contents to the general register contents with carry flag cy, and stores the result in general register indentified as r. when cmp=1, (r) + (m) + cy the result is not stored in the register. carry flag cy and zero flag z are changed according to the result. by using this addc instruction, two or more words can be easily added. sets carry flag cy, if a carry occurs as a result of the addition; resets the carry flag cy if no carry occurs. if the addition result is other than zero, zero flag z is reset, regardless of compare flag cmp. if the addition result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the addition result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. addition can be executed in binary 4-bit or bcd. the bcd flag for program status word psword specifies which kind of addition is to be executed. <3> example 1 adds the 12-bit contents for addresses 0.0dh through 0.0fh to the 12-bit contents for addresses 0.2dh through 0.2fh, and stores the result in the 12-bit contents for address 0.0dh to 0.0fh, when row address 0 (0.00h-0.0fh) of bank 0 is specified as a general register: (0.0fh) ? ( 0.0fh) + (0.2fh) (0.0eh) ? ( 0.0eh) + (0.2eh) + cy (0.0dh) ? ( 0.0dh) + (0.2dh) + cy mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh
chapter 18 instruction set 196 mem02d mem 0.2dh mem02e mem 0.2eh mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 add mem00f, mem02f addc mem00e, mem02e addc mem00d, mem02d example 2 shifts the 12-bit contents for addresses 0.2dh through 0.2fh and the carry flag by 1 bit to the left, when row address 2 in bank 0 (0.20h-0.2fh) is specified as a general register. mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh mem02d mem 0.2dh mem02e mem 0.2eh mem02f mem 0.2fh mov rph, #00h ; general register bank 0 mov rpl, #04h ; general register row address 2 mov bank, #00h ; data memory bank 0 addc mem00f, mem02f addc mem00e, mem02e addc mem00d, mem02d example 3 adds the address 0.0fh contents to the addresses 0.40h through 0.4fh contents, and stores the result in address 0.0fh: cy (carry flag) bank 0 address 0dh bank 0 address 0eh bank 0 address 0fh cy (carry flag)
chapter 18 instruction set 197 (0.0fh) ? (0.0fh) + (0.40h) + (0.41h) + + (0.4fh) mem00f mem 0.0fh mem000 mem 0.00h mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h mov ixl, #00h loop1: set1 ixe ; ixe flag ? 1 add mem00f, mem000 clr1 ixe ; ixe flag ? 0 inc ix ; ix ? ix + 1 ske ixl, #0 jmp loop1 example 4 adds the 12-bit contents for addresses 0.40h through 0.42h to the 12-bit contents for addresses 0.0dh through 0.0fh, and stores the result in 12-bit contents for addresses 0.0dh through 0.0fh: (0.0dh) ? (0.0dh) + (0.40h) (0.0eh) ? (0.0eh) + (0.41h) + cy (0.0fh) ? (0.0fh) + (0.42h) + cy mem000 mem 0.00h mem001 mem 0.01h mem002 mem 0.02h mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00001000000 (0.40h) mov ixm, #04h mov ixl, #00h set1 ixe ; ixe flag ? 1 add mem00d, mem000 ; (0.0dh) ? (0.0dh) + (0.40h)
chapter 18 instruction set 198 addc mem00e, mem001 ; (0.0eh) ? (0.0eh) + (0.41h) addc mem00f, mem002 ; (0.0fh) ? (0.0fh) + (0.42h) (4) addc m, #n4 add immediate data to data memory with carry flag <1> op code 10 87 43 0 10010 m r m c n4 <2> function when cmp=0, (m) ? (m) + n4 + cy add immediate data to the data memory contents with carry flag (cy), and stores the result in data memory. when cmp=1, (m) + n4 + cy the result is not stored in the data memory, and carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a carry occurs as a result of the addition. resets the carry flag cy, if no carry occurs. if the addition result is other than zero, zero flag z is reset, regardless of compare flag cmp. if the addition result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the addition result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. addition can be executed in binary 4-bit or bcd. the bcd flag for psword specifies which kind of addition is to be executed. <3> example 1 adds 5 to the 12-bit contents for addresses 0.0dh through 0.0fh, and stores the result in addresses 0.0dh through 0.0fh; (0.0fh) ? (0.0fh) + 05h (0.0eh) ? (0.0eh) + cy (0.0dh) ? (0.0dh) + cy mem00d mem 0.0dh mem00e mem 0.0eh
chapter 18 instruction set 199 mem00f mem 0.0fh mov bank, #00h ; data memory bank 0 add mem00f, #05h addc mem00e, #00h addc mem00d, #00h example 2 adds 5 to the 12-bit contents for addresses 0.4dh through 0.4fh, and stores the result in addresses 0.4dh through 0.4fh; (0.4fh) ? (0.4fh) + 05h (0.4eh) ? (0.4eh) + cy (0.4dh) ? (0.4dh) + cy mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh mov bank, #00h ; data memory bank 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h mov ixl, #00h set1 ixe ; ixe flag ? 1 add mem00f, #5 ; (0.4fh) ? (0.4fh) + 5h addc mem00e, #0 ; (0.4eh) ? (0.4eh) + cy addc mem00d, #0 ; (0.4dh) ? (0.4dh) + cy (5) inc ar increment address register <1> op code 10 87 43 0 00111 000 1001 0000 <2> function ar ? ar + 1 increments the address register ar contents.
chapter 18 instruction set 200 <3> example 1 adds 1 to the 16-bit contents for ar3 through ar0 (address registers) in the system register and stores the result in ar3 through ar0: ar0 ? ar0 + 1 ar1 ? ar1 + cy ar2 ? ar2 + cy ar3 ? ar3 + cy inc ar this instruction can be rewritten as follows, with addition instructions: add ar0, #01h addc ar1, #00h addc ar2, #00h addc ar3, #00h example 2 transfers table data, 16 bits (1 address) at a time, to dbf (data buffer), using the table reference instruction (for details, refer to 10.2.3 table reference ): ; address table data 010h dw 0f3ffh 011g dw 0a123h 012h dw 0fff1h 013h dw 0fff5h 014h dw 0ff11h mov ar3, #0h ; sets table data address mov ar2, #0h ; 0010h in address register mov ar1, #1h ; mov ar0, #0h loop: movt @ar ; reads table data to dbf : : : ; table data reference processing :
chapter 18 instruction set 201 inc ar ; increments address register by 1 br loop <4> note the higher 6 bits of address register are fixed to 0. only lower 10 bits can be used. (6) inc ix increment index register <1> op code 10 87 43 0 00111 000 1000 0000 <2> function ix ? ix + 1 increments the index register ix contents. <3> example 1 adds 1 to the total of 12-bit contents for ixh, ixm, and ixl (index registers) in the system register and stores the result in ixh, ixm, and ixl; ; ixl ? ixl + 1 ; ixm ? ixm + cy ; ixh ? ixh + cy inc ix this program can be rewritten as follows, with addition instructions: add ixl, #01h addc ixm, #00h addc ixh, #00h example 2 clears all the contents for data memory addresses 0.00h through 0.73h to 0, using the index register: mov ixh, #00h ; sets index register contents in 00h in bank 0 mov ixm, #00h mov ixl, #00h ram clear: mem000 mem 0.00h set1 ixe ; ixe flag ? 1
chapter 18 instruction set 202 mov mem000, #00h ; writes 0 to data memory indicated by index register clr1 ixe ; ixe flag ? 0 inc ix set2 cmp, z ; cmp flag ? 1, z flag ? 1 sub ixl, #03h ; checks whether index register contents subc ixm, #07h ; are 73h in bank 0 subc ixh, #00h ; skt1 z ; loops until contents of index register becomes br ram clear ; 73h of bank 0 18.5.2 subtraction instructions (1) sub r, m subtract data memory from general register <1> op code 10 87 43 0 00001 m r m c r <2> function when cmp=0, (r) ? (r) C (m) subtracts the data memory contents from the general register contents, and stores the result in general register. when cmp=1, (r) C (m) the result is not stored in the register. carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a borrow occurs as a result of the subtraction. resets the carry flag, if no borrow occurs. if the subtraction result is other than zero, zero flag z is reset, regardless of compare flag cmp. if the subtraction result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the subtraction result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. subtraction can be executed in binary 4-bit or bcd. the bcd flag for program status word psword specifies which kind of subtraction is to be executed.
chapter 18 instruction set 203 <3> example 1 subtracts the address 0.2fh contents from the address 0.03h contents, and stores the result in address 0.03h, when row address 0 (0.00h-0.0fh) in bank 0 is specified as a general register (rph=0, rpl=0): (0.03h) ? (0.03h) + (0.2fh) mem003 mem 0.03h mem02f mem 0.2fh sub mem003, mem02f example 2 subtracts the address 0.2fh contents from the address 0.23h contents, when row address 2 (0.20h-0.2fh) in bank 0 is specified as the general register (rph=0, rpl=4), and stores the result in address 0.23h: (0.23h) ? (0.23h) C (0.2fh) mem023 mem 0.23h mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #04h ; general register row address 2 sub mem023, mem02f example 3 subtracts the address 0.6fh contents from the address 0.03h contents and stores the result in address 0.03h. at this time, data memory address 0.6fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=4, and ixl=0, i.e., ix=0.40h. (0.03h) ? (0.03h) + (0.6fh) mem003 mem 0.03h mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h ; mov ixl, #00h ;
chapter 18 instruction set 204 set1 ixe ; ixe flag ? 1 sub mem003, mem02f ; ix 00001000000b (0.40h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00001101111b (0.6fh) example 4 subtracts the address 0.3fh contents from the address 0.03h contents and stores the result in address 0.03h. at this time, data memory address 0.3fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=1, and ixl=0, i.e., ix=0.10h. (0.03h) ? (0.03h) + (0.3fh) mem003 mem 0.03h mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00000010000b (0.10h) mov ixm, #01h ; mov ixl, #00h ; set1 ixe ; ixe flag ? 1 sub mem003, mem02f ; ix 00000010000b (0.10h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00000111111b (0.3fh) <4> note the first operand for the sub r, m instruction must be a general register address. therefore, if the instruction is described as follows, address 03h is specified as a register: mem013 mem 0.13h mem02f mem 0.2fh sub mem013, mem02f general register address must be in 00h-0fh range (set register pointer row address other than 1). when the cmp flag=1, the subtraction result is not stored. when the bcd flag=1, the bcd result is stored.
chapter 18 instruction set 205 (2) sub m, #n4 subtract immediate data from data memory <1> op code 10 87 43 0 10001 m r m c n4 <2> function when cmp=0, (m) ? (m) C n4 subtracts immediate data from the data memory contents, and stores the result in data memory. when cmp=0, (m) C n4 the result is not stored in data memory. carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a borrow occurs as a result of the subtraction. resets the carry flag cy, if no borrow occurs. if the subtraction result is other than zero, zero flag z is reset, regardless of compare flag cmp. if the subtraction result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the subtraction result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. subtraction can be executed in binary 4-bit or bcd. the bcd flag for program status word psword specifies which kind of subtraction is to be executed. <3> example 1 subtracts 5 from the address 0.2fh contents, and stores the result in address 0.2fh: (0.2fh) ? (0.2fh) C 5 mem02f mem 0.2fh sub mem02f, #05h example 2 to subtract 5 from the address 0.6fh contents and store the result in address 0.6fh. at this time, data memory address 0.6fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=4, and ixl=0, i.e., ix=0.40h.
chapter 18 instruction set 206 (0.6fh) ? ( 0.6fh) C 5 address obtained as a result of oring index register contents, 0.40h, and data memory address 0.2fh mem02f mem 0.2fh mov bank, #00h ; data memory bank 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h ; mov ixl, #00h ; set1 ixe ; ixe flag ? 1 sub mem02f, #05h ; ix 00001000000b (0.40h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00001101111b (0.6fh) example 3 subtracts 5 from the address 0.2fh contents and stores the result in address 0.2fh. at this time, data memory address 0.2fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=0, and ixl=0, i.e., ix=0.00h. (0.2fh) ? ( 0.2fh) C 5 address obtained as a result of oring index register contents, 0.00h, and data memory address 0.2fh mem02f mem 0.2fh mov bank0, #00h ; data memory bank 0 mov ixh, #00h ; ix ? 00000000000b (0.00h) mov ixm, #00h ; mov ixl, #00h ; set1 ixe ; ixe flag ? 1 sub mem02f, #05h ; ix 00000000000b (0.00h) ; bank operand or) 00000101111b (0.2fh) ; specified address 00000101111b (0.2fh) <4> note when the cmp flag=1, the subtraction result is not stored. when the bcd flag=1, the bcd result is stored.
chapter 18 instruction set 207 (3) subc r, m subtract data memory from general register with carry flag <1> op code 10 87 43 0 00011 m r m c r <2> function when cmp=0, (r) ? (r) C (m) C cy subtracts the data memory contents and the value of carry flag cy from the general register contents. stores the result in general register. by using this subc instruction, 2 or more words can be easily subtracted. when cmp=1, (r) C (m) C cy the result is not stored in the register. carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a borrow occurs as a result of the subtraction. resets the carry flag cy, if no borrow occurs. if the subtraction result is other than zero, zero flag z is reset, regardless of compare flag cmp. if the subtraction result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the subtraction result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. subtraction can be executed in binary 4-bit or bcd. the bcd flag for program status word psword specifies which kind of subtraction is to be executed. <3> example 1 subtracts the 12-bit contents for addresses 0.2dh through 0.2fh from the 12-bit contents for addresses 0.0dh through 0.0fh and stores the result in 12 bits for addresses 0.0dh through 0.0fh, when row address 0 (0.00h-0.0fh) in bank 0 is specified as a general register: (0.0fh) ? (0.0fh) C (0.2fh) (0.0eh) ? (0.0eh) C (0.2eh) C cy (0.0dh) ? ( 0.0dh) + (0.2dh) C cy mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh
chapter 18 instruction set 208 mem02d mem 0.2dh mem02e mem 0.2eh mem02f mem 0.2fh sub mem00f, mem02f subc mem00e, mem02e subc mem00d, mem02d example 2 subtracts the 12-bit contents for addresses 0.40h through 0.42h from the 12-bit contents for addresses 0.0dh through 0.0fh, and stores the result in 12 bits for addresses 0.0dh through 0.0fh. (0.0dh) ? (0.0dh) C (0.40h) (0.0eh) ? (0.0eh) C (0.41h) C cy (0.0fh) ? (0.0fh) C (0.42h) C cy mem000 mem 0.00h mem001 mem 0.01h mem002 mem 0.02h mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh mov bank, #00h ; data memory bank 0 mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h ; mov ixl, #00h ; set1 ixe ; ixe flag ? 1 sub mem00d, mem000 ; (0.0dh) ? (0.0dh) C (0.40h) subc mem00e, mem001 ; (0.0eh) ? (0.0eh) C (0.41h) subc mem00f, mem002 ; (0.0fh) ? (0.0fh) C (0.42h) example 3 compares the 12-bit contents for addresses 0.0ch through 0.0fh with the 12-bit contents for addresses 0.00h through 0.03h. jumps to lab1, if the contents are the same, if not, jumps to lab2: mem000 mem 0.00h mem001 mem 0.01h mem002 mem 0.02h mem003 mem 0.03h
chapter 18 instruction set 209 mem00c mem 0.0ch mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh set2 cmp, z ; cmp flag ? 1, z flag ? 1 sub mem000, mem00c ; contents for addresses 0.00h-0.03h do not change, subc mem001, mem00d ; because cmp flag is set subc mem002, mem00e ; subc mem003, mem00f ; skf1 z ; z flag=1, if contents are the same; if not, z flag=0 br lab1 ; br lab2 lab1: lab2: (4) subc m, #n4 subtract immediate data from data memory with carry flag <1> op code 10 87 43 0 10011 m r m c n4 <2> function when cmp=0, (m) ? (m) C n4 C cy subtracts immediate data and the value of carry flag cy from the data memory contents, and stores the result in data memory. when cmp=1, (m) C n4 C cy the result is not stored in the data memory. carry flag cy and zero flag z are changed, according to the result. sets carry flag cy, if a borrow occurs as a result of the subtraction. resets the carry flag cy, if no borrow occurs. if the subtraction result is other than zero, zero flag z is reset, regardless of compare flag cmp.
chapter 18 instruction set 210 if the subtraction result is zero, with the compare flag reset (cmp=0), the zero flag z is set. if the subtraction result is zero, with the compare flag set (cmp=1), the zero flag z is not changed. subtraction can be executed in binary or bcd. the bcd flag for program status word psword specifies which kind of subtraction is to be executed. <3> example 1 subtracts 5 from the 12-bit contents for addresses 0.0dh through 0.0fh and stores the result in addresses 0.0dh through 0.0fh: (0.0fh) ? (0.0fh) C 05h (0.0eh) ? (0.0eh) C cy (0.0dh) ? (0.0dh) C cy mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh sub mem00f, #05h subc mem00e, #00h subc mem00d, #00h example 2 to subtract 5 from the 12-bit contents for addresses 0.4dh through 0.4fh and store the result in addresses 0.4dh through 0.4fh: (0.4fh) ? (0.4fh) C 05h (0.4eh) ? (0.4eh) C cy (0.4dh) ? (0.4dh) C cy mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh mov bank, #00h ; data memory bank 0 mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h ; mov ixl, #00h ; set1 ixe ; ixe flag ? 1 sub mem00f, #5 ; (0.4fh) ? (0.4fh) C 5 subc mem00e, #0 ; (0.4eh) ? (0.4eh) C cy subc mem00d, #0 ; (0.4dh) ? (0.4dh) C cy
chapter 18 instruction set 211 example 3 compares the 12-bit contents for addresses 0.00h through 0.03h with immediate data 0a3fh. jumps to lab1, if the contents are the same; if not, jumps to lab2: mem000 mem 0.00h mem001 mem 0.01h mem002 mem 0.02h mem003 mem 0.03h set2 cmp, z ; cmp flag ? 1, z flag ? 1 sub mem000, #0h ; contents for addresses 0.00hC0.03h do not subc mem001, #0ah ; change, because cmp flag is set subc mem002, #3h ; subc mem003, #0fh ; skf1 z ; z flag=1, if contents are the same; if not, z flag=0 br lab1 ; br lab2 lab1: lab2: 18.5.3 logical operation instructions (1) or r, m or between general register and data memory <1> op code 10 87 43 0 00110 m r m c r <2> function (r) ? (r) (m) ors the general register contents with data memory contents. stores the result in general register.
chapter 18 instruction set 212 <3> example 1 to or the address 0.03h contents (1010b) and the address 0.2fh contents (0111b) and store the result (1111b) in address 0.03h: (0.03h) ? (0.03h) (0.2fh) 1010 address 03h 0111 address 2fh 1111 address 03h or mem003 mem 0.03h mem02f mem 0.2fh mov mem003, #1010b mov mem02f, #0111b or mem003, mem02f (2) or m, #n4 or between data memory and immediate data <1> op code 10 87 43 0 10110 m r m c n4 <2> function (m) ? (m) n4 ors the data memory contents and immediate data. stores the result in data memory. <3> example 1 to set bit 3 (msb) for address 0.03h: (0.03h) ? (0.03h) 1000b address 0.03 1 : don't care mem003 mem 0.03h or mem003, #1000b
chapter 18 instruction set 213 example 2 sets all the bits for address 0.03h: mem003 mem 0.03h or mem003, #1111b or, mem003 mem 0.03h mov mem003, #0fh (3) and r, m and between general register and data memory <1> op code 10 87 43 0 00100 m r m c r <2> function (r) ? (r) (m) ands the general register contents with data memory contents and stores the result in general register. <3> example 1 ands the address 0.03h (1010b) contents and the address 0.2fh (0110b) contents. stores the result (0010b) in address 0.03h: (0.03h) ? (0.03h) (0.2fh) mem003 mem 0.03h mem02f mem 0.2fh mov mem003, #1010b mov mem02f, #0110b and mem003, mem02f 1010 address 03h 0110 address 2fh 0010 address 03h and
chapter 18 instruction set 214 (4) and m, #n4 and between data memory and immediate data <1> op code 10 87 43 0 10100 m r m c n4 <2> function (m) ? (m) n4 ands the data memory contents and immediate data. stores the result in data memory. <3> example 1 to reset bit 3 (msb) for address 0.03h. (0.03h) ? (0.03h) 0111b address 0.03h 1 : don't care mem003 mem 0.03h and mem003, #0111b example 2 to reset all the bits for address 0.03h: mem003 mem 0.03h and mem003, #0000b or, mem003 mem 0.03h mov mem003, #00h (5) xor r, m exclusive or between general register and data memory <1> op code 10 87 43 0 00101 m r m c r
chapter 18 instruction set 215 <2> function (r) ? (r) (m) exclusive-ors (xor) the general register contents with data memory contents. stores the result in general register. <3> example 1 compares the address 0.03h contents and the address 0.0fh contents. if different bits are found, set and store them in address 0.03h. if all the bits in address 0.03h are reset (i.e., the address 0.03h contents are the same as those for address 0.0fh), jumps to lbl1; otherwise, jumps to lbl2. this example is to compare the status of an alternate switch (address 0.03h contents) with the internal status (address 0.0fh contents) and to branch to changed switch processing. 1010 address 03h 0110 address 0fh 1100 address 03h xor bits chan g ed mem003 mem 0.03h mem00f mem 0.0fh xor mem003, mem00f skne mem003, #00h br lbl1 br lbl2 example 2 clears the address 0.03h contents: 0101 address 03h 0101 address 03h 0000 address 03h xor mem003 mem 0.03h xor mem003, mem003
chapter 18 instruction set 216 (6) xor m, #n4 exclusive or between data memory and immediate data <1> op code 10 87 43 0 10101 m r m c n4 <2> function (m) ? (m) n4 exclusive-ors the data memory contents and immediate data. stores the result in data memory. <3> example inverts bits 1 and 3 in address 0.03h and store the result in address 03h: mem003 mem 0.03h xor mem003, #1010b 18.5.4 judgment instruction (1) skt m, #n skip next instruction if data memory bits are true <1> op code 10 87 43 0 11110 m r m c n <2> function cmp ? 0, if (m) n=n, then skip skip the next one instruction, if the result of anding the data memory contents and immediate data n is equal to n (executes as nop instruction) 1100 address 03h 1010 0110 address 03h xor inverted bits
chapter 18 instruction set 217 <3> example 1 jumps to aaa, if bit 0 in address 03h is 1; if it is 0, jumps to bbb: skt 03h, #0001b br bbb br aaa example 2 skips the next instruction, if both bits 0 and 1 in address 03h are 1. skt 03h, #0011b b 3 b 2 b 1 b 0 skip condition 03h 11 : don't care example 3 the results of executing the following two instructions are the same: skt 13h, #1111b ske 13h, #0fh (2) skf m, #n skip next instruction if data memory bits are false <1> op code 10 87 43 0 11111 m r m c n <2> function cmp ? 0, if (m) n=0, then skip skips the next one instruction, if the result of anding the data memory contents and immediate data n is 0 (executes as nop instruction). <3> example 1 stores immediate data 00h to address 0fh in the data memory content, if bit 2 in address 13h is 0; if it is 1, jumps to abc: mem013 mem 0.13h mem00f mem 0.0fh skf mem013, #0100b br abc mov mem00f, #00h
chapter 18 instruction set 218 example 2 skips the next instruction, if both bits 3 and 0 in address 29h are 0. skf 29h, #1001b b 3 b 2 b 1 b 0 skip condition 29h 0 0 : don't care example 3 the results of executing the following two instructions are the same: skf 34h, #1111b ske 34h, #00h 18.5.5 comparison instructions (1) ske m, #n4 skip if data memory equal to immediate data <1> op code 10 87 43 0 01001 m r m c n4 <2> function (m) Cn4, skip if zero skip the next one instruction, if the data memory contents are equal to the immediate data value (executes as nop instruction). <3> example to transfer 0fh to address 24h, if the address 24h contents are 0; if not, jumps to ope1: mem024 mem 0.24h ske mem024, #00h br ope1 mov mem024, #0fh ope1 :
chapter 18 instruction set 219 (2) skne m, #n4 skip if data memory not equal to immediate data <1> op code 10 87 43 0 01011 m r m c n4 <2> function (m) Cn4, skip if not zero skips the next one instruction, if the data memory contents are not equal to the immediate data value (executes as nop instruction). <3> example jumps to xyz, if the address 1fh contents are 1 and the address 1eh contents are 3; otherwise, jumps to abc. to compare 8-bit data, this instruction is used in the following combination: 31 1eh 0011 1fh 0001 mem01e mem 0.1eh mem01f mem 0.1fh skne mem01f, #01h ske mem01e, #03h br abc br xyz the above program can be rewritten as follows, using compare and zero flags: mem01e mem 0.1eh mem01f mem 0.1fh set2 cmp, z ; cmp flag ? 1, z flag ? 1 sub mem01f, #01h subc mem01e, #03h skt1 z br abc br xyz
chapter 18 instruction set 220 (3) skge m, #n4 skip if data memory greater than or equal to immediate data <1> op code 10 87 43 0 11001 m r m c n4 <2> function (m) Cn4, skip if not borrow skips the next one instruction, if the data memory contents are equal to or greater than the immediate data value (executes as nop instruction). <3> example executes ret, if 8-bit data stored in addresses 1fh (higher) and 2fh (lower) is greater than immediate data '17h'; if not, executes retsk: mem01e mem 0.1fh mem02f mem 0.2fh skge mem01f, #1 retsk skne mem01f, #1 sklt mem02f, #8 ; 7+1 ret retsk (4) sklt m, #n4 skip if data memory less than immediate data <1> op code 10 87 43 0 11011 m r m c n4 <2> function (m) Cn4, skip if borrow skips the next one instruction, if the data memory contents are less than the immediate data value (executes as nop instruction). <3> example stores 01h in address 0fh, if the address 10h contents are greater than immediate data '6'; if not, stores 02h in address 0fh:
chapter 18 instruction set 221 mem00f mem 0.0fh mem010 mem 0.10h mov mem00f, #02h sklt mem010, #06h mov mem00f, #01h 18.5.6 rotation instructions (1) rorc r rotate right general register with carry flag <1> op code 30 00111 000 0111 r <2> function cy (r) b3 (r) b2 (r) b1 (r) b0 rotates the contents of general register indicated by r including carry flag to the right by 1 bit. <3> example 1 when row address 0 of bank 0 (0.00h-0.0fh) is specified as general register (rph=0, rpl=0), rotate the value of address 0.00h (1000b) to the right by 1 bit to make it 0100b. (0.00h) ? (0.00h) ? 2 mem000 mem 0.00h mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 clr1 cy ; cy flag ? 0 rorc mem000 example 2 when row address 0 of bank 0 (0.00h-0.0fh) is specified as general register (rph=0, rpl=0), rotate the data buffer dbf contents 0fa52h to the right by 1 bit to make dbf contents 7d29h.
chapter 18 instruction set 222 1111 0 cy 0ch 0111 1010 0dh 1101 0101 0eh 0010 0010 0fh 1001 0 cy mem00c mem 0.0ch mem00d mem 0.0dh mem00e mem 0.0eh mem00f mem 0.0fh mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 clr1 cy ; cy flag ? 0 rorc mem00c rorc mem00d rorc mem00e rorc mem00f 18.5.7 transfer instructions (1) ld r, m load data memory to general register <1> op code 10 87 43 0 01000 m r m c r <2> function (r) ? (m) stores the data memory contents to general register. <3> example 1 to store the address 0.2fh contents to address 0.03h: (0.03h) ? (0.2fh) mem003 mem 0.03h mem02f mem 0.2fh ld mem003, mem02f
chapter 18 instruction set 223 bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address example 2 stores the address 0.6fh contents to address 0.03h. at this time, data memory address 0.6fh can be specified by selecting data memory address 2fh, if ixe=1, ixh=0, ixm=4, and ixl=0, i.e., ix=0.40h. ixh ? 00h ixm ? 04h ixl ? 00h ixe flag ? 1 (0.03h) ? ( 0.6fh) address obtained as result of oring index register contents, 040h, and data memory contents, 0.2fh mem003 mem 0.03h mem02f mem 0.2fh mov ixh, #00h ; ix ? 00001000000b (0.40h) mov ixm, #04h mov ixl, #00h set1 ixe ; ixe flag ? 1 ld mem003, mem02f bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address
chapter 18 instruction set 224 (2) st m, r store general register to data memory <1> op code 10 87 43 0 11000 m r m c r <2> function (m) ? (r) stores the general register contents to data memory. <3> example 1 stores the address 0.03h contents to address 0.2fh: (0.2fh) ? (0.03h) st 2fh, 03h ; transfer general register contents to data memory bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address example 2 stores the address 0.00h contents to addresses 0.18h through 0.1fh. the data memory addresses (18h- 1fh) are specified by the index register. (0.18h) ? (0.00h) (0.19h) ? (0.00h) (0.1fh) ? (0.00h) mov ixh, #00h ; ix ? 00000000000b (0.00h) mov ixm, #00h mov ixl, #00h ; specifies data memory address 0.00h
chapter 18 instruction set 225 mem018 mem 0.18h mem000 mem 0.00h loop1: set1 ixe ; ixe flag ? 1 st mem018, mem000 ; (0.1 h) ? (0.00h) clr1 ixe ; ixe flag ? 0 inc ix ; ix ? ix+1 skge ixl, #08h br loop1 bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address (3) mov @r, m move data memory to destination indirect <1> op code 10 87 43 0 01010 m r m c r <2> function when mpe=1 (mp, (r)) ? (m) when mpe=0 (bank, m r , (r)) ? (m) stores the data memory contents to the data memory addressed by the general register contents. when mpe=0, transfer is performed in the same row address in the same bank.
chapter 18 instruction set 226 <3> example 1 stores the address 0.20h contents to address 0.2fh with the mpe flag cleared to 0. the transfer destination data memory address is at the same row address as the transfer source, and the column address is specified by the general register contents at address 0.00h. (0.2fh) ? (0.20h) mem000 mem 0.00h mem020 mem 0.20h clr1 mpe ; mpe flag ? 0 mov mem000, #0fh ; sets column address in general register mov @mem000, mem020 ; store bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address f example 2 stores the address 0.20h contents to address 0.3fh, with the mpe flag set to 1. the row address for the transfer destination data memory address is specified by the memory pointer mp contents. the column address is specified by the general register contents at address 0.00h. (0.3fh) ? (0.20h) mem000 mem 0.00h mem020 mem 0.20h mov rph, #00h ; general register bank 0 mov rpl, #00h ; general register row address 0 mov 00h, #0fh ; sets column address in general register mov mph, #00h ; sets row address in memory pointer mov mpl, #03h ; set1 mpe ; mpe flag ? 1 mov @mem000, mem020 ; store
chapter 18 instruction set 227 bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address f (4) mov m, @r move data memory to destination indirect <1> op code 10 87 43 0 11010 m r m c r <2> function when mpe=1 (m) ? (mp, (r)) when mpe=0 (m) ? (bank, m r , (r)) stores the data memory contents addressed by the general register contents to data memory. when mpe=0, transfer is performed in the same row address in the same bank. <3> example 1 stores the address 0.2fh contents to address 0.20h, with the mpe falg cleared to 0. the transfer destination data memory address is at the same row address as the transfer source. the column address is specified by the general register contents at address 0.00h. (0.20h) ? (0.2fh) mem000 mem 0.00h mem020 mem 0.20h clr1 mpe ; mpe flag ? 0 mov mem000, #0fh ; sets column address in general register mov mem020, @mem000 ; store
chapter 18 instruction set 228 bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address f example 2 stores the address 0.3fh contents to address 0.20h, with the mpe flag set to 1. the row address for the transfer source data memory is specified by the memory pointer mp contents. the column address is specified by the general register contents at address 0.00h. (0.20h) ? (0.3fh) mem000 mem 0.00h mem020 mem 0.20h mov mem000, #0fh ; sets column address in general register mov mph, #00h ; sets row address in memory pointer mov mpl, #03h ; set1 mpe ; mpe flag ? 1 mov mem020, @mem000 ; store bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef general register row address f
chapter 18 instruction set 229 (5) mov m, #n4 move immediate data to data memory <1> op code 10 87 43 0 11101 m r m c n4 <2> function (m) ? n4 stores immediate data to data memory. <3> example 1 stores immediate data 0ah to data memory address 0.50h: (0.50h) ? 0ah mem050 mem 0.50h mov mem050, #0ah example 2 stores immediate data 07h to address 0.32h, when data memory address 0.00h is specified with ixh=0, ixm=3, ixl=2, and ixe flag=1: (0.32h) ? 07h mem000 mem 0.00h mov ixh, #00h ; ix ? 00000110010b (0.32h) mov ixm, #03h mov ixl, #02h set1 ixe ; ixe flag ? 1 mov mem000, #07h (6) movt dbf, @ar move program memory data specified by ar to dbf <1> op code 10 87 43 0 00111 000 0001 0000 <2> function sp ? spC1, asr ? pc, pc ? ar, dbf ? (pc), pc ? asr, sp ? sp+1
chapter 18 instruction set 230 stores the program memory contents, addressed by address register ar, to data buffer dbf. since this instruction temporarily uses one stack level, pay attention to nesting such as subroutines and interrupts. <3> example to transfer 16 bits of table data, specified by the values for address registers ar3, ar2, ar1, and ar0 in the system register, to data buffers dbf3, dbf2, dbf1, and dbf0: ; * ; ** table data ; * address org 0010h 0010h dw 0000000000000000b ; (0000h) 0011h dw 1010101111001101b ; ( 0abcdh) ; * ; ** table reference program ; * mov ar3, #00h ; ar3 ? 00h sets 0011h in address register mov ar2, #00h ; ar2 ? 00h mov ar1, #01h ; ar1 ? 01h mov ar0, #01h ; ar0 ? 01h movt dbf, @ar ; transfers address 0011h data to dbf in this case, the data are stored in dbf, as follows: dbf3=0ah dbf2=0bh dbf1=0ch dbf0=0dh (7) push ar push address register <1> op code 00111 000 1101 0000
chapter 18 instruction set 231 <2> function sp ? spC1, asr ? ar decrements stack pointer sp and stores the address register ar value to address stack register specified by stack pointer. <3> example 1 sets 003fh in address register and stores it in stack: mov ar3, #00h mov ar2, #00h mov ar1, #03h mov ar0, #0fh push ar bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef row address 0 0 3 f stack 003f
chapter 18 instruction set 232 example 2 sets the return address for a subroutine in the address register. returns execution, if a data table exists after a subroutine: ................. ................. ................. address 0010h call sub1 ;* ;** data table ;* 0011h dw 0012h dw 0013h dw 0014h dw 1a1fh 002fh 010ah 0555fh 002fh dw 0030h 0fffh sub1: pop ar mov mov mov mov push ret ar3, ar2, ar1, ar0, ar #00h #00h #03h #00h if pop instruction is executed at this time, the contents of address register is "0011h" (the next address of call instruction).
chapter 18 instruction set 233 (8) pop ar pop address register <1> op code 00111 000 1100 0000 <2> function ar ? asr, sp ? sp+1 pops the contents of address stack register indicated by stack pointer to address register ar and then increments stack pointer sp. <3> example if the psw contents are changed, while an interrupt processing routine is being executed, the psw contents are transferred to the address register through wr at the beginning of the interrupt processing and saved to address stack register by the push instruction. before the execution returns from the interrupt routine, the address register contents are restored through wr to psw by the pop instruction. ............... .................. .................................................. ............................................ ei genetates interrupt factor peek poke push wr, psw ar0, wr ar interrupt processing routine pop peek poke ret (or reti) ar wr, ar0 psw, wr
chapter 18 instruction set 234 (9) peek wr, rf peek register file to window register <1> op code 00111 rf r 0011 rf c <2> function wr ? (rf) stores the register file contents to window register wr. <3> example stores the stack pointer sp contents at address 01h in the register file to the window register: peek wr, sp sp wr bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef row address column address 0 1 2 3 0123456789abcdef row address register file
chapter 18 instruction set 235 (10) poke rf, wr poke window register to register file <1> op code 10 87 43 0 00111 rf r 0010 rf c <2> function (rf) ? wr stores the window register wr contents to register file. <3> example 1 stores immediate data 0fh to p0dbio for the register file through the window register: mov wr, #0fh poke p0dbio, wr ; sets all of p0d 0 , p0d 1 , p0d 2 , and p0d 3 in output mode wr bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef row address column address 0 1 2 3 0123456789abcdef row address register file p0dbio
chapter 18 instruction set 236 <4> note among register files, data memories can be seen at 40h-7fh (74h-7fh is system register). therefore, the peek and poke instructions can access addresses 40h through 7fh in each data memory bank, in addition to the register file. for example, these instructions can be used as follows: mem05f mem 0.5fh peek wr, psw ; stores psw (7fh) contents in system register to wr poke mem05f, wr ; stores wr contents to address 5fh in data memory (11) get dbf, p get peripheral data to data buffer <1> op code 10 87 43 0 00111 p h 1011 p l <2> function dbf ? (p) stores the peripheral register contents to data buffer dbf. <3> example 1 stores the 8-bit contents for shift register siosfr in the serial interface to data buffers dbf0 and dbf1: get dbf, siosfr wr bank 0 column address psw 0 1 2 3 4 5 6 7 0123456789abcdef row address register file data memory poke 5fh, wr peek wr, psw system register
chapter 18 instruction set 237 <4> note 1 the data buffer is assigned to addresses 0ch, 0dh, 0eh, and 0fh in bank 0 for the data memory, regardless of the bank register value. note 2 up to 16 bits in the data buffer are available. when a peripheral circuit is accessed by the get instruction, the number of bits, by which the circuit is to be accessed, differs depending on the circuit. for example, if the get instruction is executed to access a peripheral circuit, which should be accessed in 8-bit units, data is stored in the lower 8 bits for the data buffer dbf (dbf1, dbf0). data buffer dbf3 retain dbf2 retain dbf1 b 7 dbf0 b 0 get actual bits b 7 b 0 data of peripheral hardware bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef row address dbf bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef dbf row address 1 2 peripheral circit 12h siosfr
chapter 18 instruction set 238 (12) put p, dbf put data buffer to peripheral <1> op code 10 87 43 0 00111 p h 1010 p l <2> function (p) ? dbf stores the data buffer dbf contents to peripheral register. <3> example sets 0ah and 05h to data buffers dbf1 and dbf0, respectively, and transfers them to a peripheral register, shift register (siosfr) for serial interface: mov bank, #00h ; data memory bank 0 mov dbf0, #05h mov dbf1, #0ah put siosfr dbf <4> note up to 16 bits in the data buffer are available. when a peripheral circuit is accessed by the put instruction, the number of bits, by which the circuit is to be accessed, differs depending on the circuit. for example, if the put instruction is executed to access the shift register sio, which should be accessed in 8-bits units, only the lower 8 bits for the data buffer dbf (dbf1, dbf0) are transferred (dbf3 and dbf2 are not transferred). bank 0 column address system register 0 1 2 3 4 5 6 7 0123456789abcdef dbf row address a 5 peripheral circit 0a5h siosfr
chapter 18 instruction set 239 data buffer dbf3 don't care dbf2 don't care dbf1 b 7 dbf0 b 0 put actual bits b 7 b 0 data of peripheral hardware b 6 b 5 b 4 b 3 b 2 b 1 18.5.8 branch instructions (1) br addr branch to the address <1> op code 10 0 01100 addr <2> function pc ? addr branches to an address specified by addr. <3> example fly lab 0fh ; defines fly=0fh : : br fly ; jumps to address 0fh : : br loop1 ; jumps to loop1 : : br $+2 ; jumps to an address 2 addresses lower than current address : : br $C3 ; jumps to an address 3 addresses higher than current address : : loop1:
chapter 18 instruction set 240 (2) br @ar branch to the address specified by address register <1> op code 00111 000 0100 0000 <2> function pc ? ar branches to the program address, specified by address register ar. <3> example 1 sets 003fh in address register ar (ar0-ar3) and jumps to address 003fh by using the br @ar instruction: mov ar3, #00h ; ar3 ? 00h mov ar2, #00h ; ar2 ? 00h mov ar1, #03h ; ar1 ? 03h mov ar0, #0fh ; ar0 ? 0fh br @ar ; jumps to address 003fh example 2 changes the branch destination according to the data memory address 0.10h contents, as follows: 0.10h contents branch destination label 00h ? aaa 01h ? bbb 02h ? ccc 03h ? ddd 04h ? eee 05h ? fff 06h ? ggg 07h ? hhh 08h-0fh ? zzz ; * ; ** jump table address ; * 0010h br aaa 0011h br bbb 0012h br ccc
chapter 18 instruction set 241 0013h br ddd 0014h br eee 0015h br fff 0016h br ggg 0017h br hhh 0018h br zzz : : : mem010 mem 0.10h mov rph, #00h ; general register bank 0 mov rpl, #02h ; general register row address 1 mov ar3, #00h ; ar3 ? 00h sets ar to 001 h mov ar2, #00h ; ar2 ? 00h mov ar1, #01h ; ar1 ? 01h st ar0, #mem010 ; ar0 ? 0.10h skf ar0, #1000b ; sets 08h in ar0, if ar0 contents are greater than 08h and ar0, #1000b ; br @ar <4> note the higher 6 bits of address register are fixed to 0. only lower 10 bits can be used. 18.5.9 subroutine instructions (1) call addr call subroutine <1> op code 10 0 11100 addr <2> function sp ? spC1, asr ? pc, pc ? addr
chapter 18 instruction set 242 increments the program counter pc value, stores it to stack, and branches to a subroutine specified by addr. <3> example 1 .................. ............ .................. sub: ret call sub1 main example 2 ............... ............ ........... sub1: call sub1 main call sub2 ret ........... ........... sub2: call sub3 ret ........... ............................... sub3: ret (2) call @ar call subroutine specified by address register <1> op code 00111 000 0101 0000 <2> function sp ? spC1, asr ? pc, pc ? ar increments and saves to the stack the program counter pc value, and branches to a subroutine that starts from the address specified by address register ar.
chapter 18 instruction set 243 <3> example 1 sets 0020h in address register ar (ar0-ar3) and calls the subroutine at address 0020h with the call @ar instruction: mov ar3, #00h ; ar3 ? 00h mov ar2, #00h ; ar2 ? 00h mov ar1, #02h ; ar1 ? 02h mov ar0, #00h ; ar0 ? 00h call @ar ; calls subroutine at address 0020h example 2 calls the following subroutine by the data memory address 0.10h contents: 0.10h contents subroutine 00h ? sub1 01h ? sub2 02h ? sub3 03h ? sub4 04h ? sub5 05h ? sub6 06h ? sub7 07h ? sub8 08h-0fh ? sub9
chapter 18 instruction set 244 sub4: set .................................... sub5: ret .................................... sub6: ret .................................... sub7: ret .................................... sub8: ret .................................... sub9: ret .................................... sub1: ret .................................... sub2: ret .................................... sub3: ret .................................... ......... ............. ;* ;**jump table for subroutine address ;* 0010h br sub1 0011h br sub2 0012h br sub3 0013h br sub4 0014h br sub5 0015h br sub6 0016h br sub7 0017h br sub8 0018h br sub9 ............. ............. mov mov mov mov mov st skf and call rph, rpl, ar3, ar2, ar1, ar0, ar0, ar0, @ar, #00h #02h #00h #00h #01h 10h #1000b #1000b ; general register bank 0 ; general register row address 1 ; ar3 00h address register 001 h ; ar2 00h ; ar1 01h ; ar0 0.10h ; if the content of ar0 is larger than 08h, ; set ar0 content to 08h to jump table returns here when executing ret instruction in each subroutine <4> note the higher 6 bits of address register are fixed to 0. only lower 10 bits can be used.
chapter 18 instruction set 245 (3) ret return to the main program from subroutine <1> op code 10 87 43 0 00111 000 1110 0000 <2> function pc ? asr, sp ? sp+1 instruction to return to the main program from a subroutine. restores the return address, saved to the stack by the call instruction, to the program counter. <3> example (4) retsk return to the main program then skip next instruction <1> op code 00111 001 1110 0000 <2> function pc ? asr, sp ? sp+1 and skip instruction to return to the main program from a subroutine. skips the instruction next to the call instruction (executes as nop instruction). therefore, restores the return address, saved to the stack by the call instruction, to program counter pc and then increments the program counter. .................... ............ ............................... call sub1 sub1 ret
chapter 18 instruction set 246 <3> example executes the ret instruction, if the lsb (least significant bit) content for address 25h in the data memory (ram) is 0. the execution is returned to the instruction next to the call instruction. if the lsb is 1, executes the retsk instruction. the execution is returned to the instruction following the one next to the call instruction (in this example, add 03h, 16h). .................. ................... ............................. call br add sub1 loop 03h, 16h sub1 skf retsk ret 25h, #0001b ; lsb of 25h is "1" ; lsb of 25h is "0" (5) reti return to the main program from interrupt service routine <1> op code 00111 100 1110 0000 <2> function pc ? asr, intr ? intsk, sp ? sp+1 instruction to return to the main program, from an interrupt service program. restores the return address, saved to the stack by a vector interrupt, to the program counter. part of the system register is also returned to the status before the occurrence of the vector interrupt. <3> note 1 the system register contents that are automatically saved (i.e., that can be restored by the reti instruction) when an interrupt occurs is psword. note 2 if the reti instruction is used, instead of the ret instruction, in an ordinary subroutine, the contents of the bank (which are to be saved when an interrupt occurs) are changed to the contents of the interrupt stack, when the execution has returned to the return address. consequently, an unpredictable status may be assumed. therefore, use the ret (or retsk) instruction to return from a subroutine.
chapter 18 instruction set 247 18.5.10 interrupt instructions (1) ei enable interrupt <1> op code 00111 000 1111 0000 <2> function intef ? 1 enables a vectored interrupt. the interrupt is enabled, after the instruction next to the ei instruction has been executed. <3> example 1 as shown in the following example, the interrupt request is accepted after the instruction next to that, that has accepted the interrupt, has been completely executed (excluding an instruction that manipulates program counter). the flow then shifts to the vector address note1 . notes 1. the vector address differs, depending on the interrupt to be accepted. refer to table 14- 1 interrupt source types. ................ ..................... generating interrupt request mov add add 0ah, 0bh, 0ch, #00h #01h #01h generating interrupt request ei ............ di ei .............. mov sub 0ah, 0bh, #01h #01h ........... ei ret ..................... note 2 interrupt service routine (vecter address)
chapter 18 instruction set 248 2. the interrupt accepted in this example (an interrupt request is generated after the ei instruction has been executed and the execution flow shifts to an interrupt service routine) is the interrupt, whose interrupt enable flag (ip ) is set. the interrupt request generation without the interrupt enable flag set does not change the program flow, after the ei instruction has been executed (therefore, the interrupt is not accepted). however, interrupt request flag (irq ) is set, and the interrupt is accepted, as soon as the interrupt enable flag is set. example 2 an example of an interrupt, which occurs in response to an interrupt request being accepted when program counter pc is being executed: ................ ..................... generating interrupt request br abc ei ............ mov add 0ah, 0bh, #00h #01h ei ret ..................... interrupt service routine (vecter address) abc: ............ (2) di disable interrupt <1> op code 00111 001 1111 0000 <2> function intef ? 0 instruction to disable a vectored interrupt. <3> example refer to example 1 in (1) ei.
chapter 18 instruction set 249 18.5.11 other instructions (1) stop s stop cpu and release by condition s <1> op code 30 00111 010 1111 s <2> function stops the system clock and places the device in the stop mode. in the stop mode, the power dissipation for the device is minimized. the condition, under which the stop mode is to be released, is specified by operand (s). for the stop releasing condition (s), refer to 15.3. (2) halt h halt cpu and release by condition h <1> op code 30 00111 011 1111 h <2> function places the device in the halt mode. in the halt mode, the power dissipation for the device is reduced. the condition, under which the halt mode is to be released, is specified by operand (h). for halt releasing condition (h), refer to 15.2 halt mode. (3) nop no operation <1> op code 00111 100 1111 0000 <2> function performs nothing and consumes one machine cycle.
[memo] 250
chapter 19 assembler reserved words 19.1 mask option pseudo instructions to create m pd17120, 17121, 17132, and 17133 programs, it is necessary to specify whether pins that can have pull-up resistors have pull-up resistors. this is done in the assembler source program using mask option pseudo instructions. to set the mask option, note that d171 .opt file in the as171 ( m pd171 device file) must be in the current directory at assembly time. specify mask options for the following pins: ? reset pin ? port 0d (p0d 3 , p0d 2 , p0d 1 , p0d 0 ) ? port 0e (p0e 1 , p0e 0 ) 19.1.1 option and endop pseudo instructions the block from the option pseudo instruction to the endop pseudo instruction is defined as the option definition block. the format for the mask option definition block is shown below. only the three pseudo instructions listed in table 19-1 can be described in this block. format: symbol mnemonic operand comment [label:] option [;comment] ? ? ? ? endop 251
chapter 19 assembler reserved words 252 19.1.2 mask option definition pseudo instructions table 19-1 lists the pseudo instructions which define the mask options for each pin. table 19-1. mask option definition pseudo instructions mask option pseudo instruction reset optres 1 open (without pull-up resistor) pullup (with pull-up resistor) p0d 3 -p0d 0 optp0d 4 open (without pull-up resistor) pullup (with pull-up resistor) p0e 1 , p0e 0 optp0e 2 open (without pull-up resistor) pullup (with pull-up resistor) the optres format is shown below. specify the reset mask option in the operand field. symbol mnemonic operand comment [label:] optres (reset) [;comment] the optp0d format is shown below. specify mask options for all pins of port 0d. specify the pins in the operand field starting at the first operand in the order p0d 3 , p0d 2 , p0d 1 , then p0d 0 . symbol mnemonic operand comment [label:] optp0d (p0d 3 ), (p0d 2 ), (p0d 1 ), (p0d 0 ) [;comment] the optp0e is shown below. specify mask options for all pins of port 0e. specify the pins in the operand field starting at the first operand in the order p0e 1 , p0e 0 . symbol mnemonic operand comment [label:] optp0e (p0e 1 ), (p0e 0 ) [;comment] pin number of operands parameter name
chapter 19 assembler reserved words 253 example of describing mask options reset pin: pull-up p0d 3 : open, p0d 2 : open, p0d 1 : pull-up, p0d 0 : pull-up, p0e 1 : pull-up, p0e 0 : open symbol mnemonic operand comment ; m pd17133 setting mask options: option ; optres pullup optp0d open, open, pullup, pullup optp0e pullup, open ; endop
chapter 19 assembler reserved words 254 19.2 reserved symbols the reserved symbols defined in the m pd17120 subseries device file (as1712 , as1713 ) are listed below. 19.2.1 list of reserved symbols ( m pd17120, 17121) system register (sysreg) symbol name attribute value read/write description ar3 mem 0.74h r bits 15 to 12 of the address register ar2 mem 0.75h r/w bits 11 to 8 of the address register ar1 mem 0.76h r/w bits 7 to 4 of the address register ar0 mem 0.77h r/w bits 3 to 0 of the address register wr mem 0.78h r/w window register bank mem 0.79h r/w bank register ixh mem 0.7ah r/w index register high mph mem 0.7ah r/w data memory row address pointer high mpe flg 0.7ah.3 r/w memory pointer enable flag ixm mem 0.7bh r/w index register middle mpl mem 0.7bh r/w data memory row address pointer low ixl mem 0.7ch r/w index register low rph mem 0.7dh r/w general register pointer high rpl mem 0.7eh r/w general register pointer low psw mem 0.7fh r/w program status word bcd flg 0.7eh.0 r/w bcd flag cmp flg 0.7fh.3 r/w compare flag cy flg 0.7fh.2 r/w carry flag z flg 0.7fh.1 r/w zero flag ixe flg 0.7fh.0 r/w index enable flag data buffer (dbf) symbol name attribute value read/write description dbf3 mem 0.0ch r/w dbf bits 15 to 12 dbf2 mem 0.0dh r/w dbf bits 11 to 8 dbf1 mem 0.0eh r/w dbf bits 7 to 4 dbf0 mem 0.0fh r/w dbf bits 3 to 0
chapter 19 assembler reserved words 255 ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... port register symbol name attribute value read/write description p0e1 flg 0.6fh.1 r/w port 0e bit 1 p0e0 flg 0.6fh.0 r/w port 0e bit 0 p0a3 flg 0.70h.3 r/w port 0a bit 3 p0a2 flg 0.70h.2 r/w port 0a bit 2 p0a1 flg 0.70h.1 r/w port 0a bit 1 p0a0 flg 0.70h.0 r/w port 0a bit 0 p0b3 flg 0.71h.3 r/w port 0b bit 3 p0b2 flg 0.71h.2 r/w port 0b bit 2 p0b1 flg 0.71h.1 r/w port 0b bit 1 p0b0 flg 0.71h.0 r/w port 0b bit 0 p0c3 flg 0.72h.3 r/w port 0c bit 3 p0c2 flg 0.72h.2 r/w port 0c bit 2 p0c1 flg 0.72h.1 r/w port 0c bit 1 p0c0 flg 0.72h.0 r/w port 0c bit 0 p0d3 flg 0.73h.3 r/w port 0d bit 3 p0d2 flg 0.73h.2 r/w port 0d bit 2 p0d1 flg 0.73h.1 r/w port 0d bit 1 p0d0 flg 0.73h.0 r/w port 0d bit 0 register file (control register) (1/2) symbol name attribute value read/write description sp mem 0.81h r/w stack pointer sioen flg 0.8ah.0 r/w sio enable flag int flg 0.8fh.0 r int pin status flag pdresen flg 0.90h.0 r/w power-down reset enable flag tmen flg 0.91h.3 r/w timer enable flag tmres flg 0.91h.2 r/w timer reset flag tmck1 flg 0.91h.1 r/w timer count pulse selection flag bit 1 tmck0 flg 0.91h.0 r/w timer count pulse selection flag bit 0 tmosel flg 0.92h.0 r/w timer output port/port selection flag siots flg 0.9ah.3 r/w sio start flag siohiz flg 0.9ah.2 r/w so pin status siock1 flg 0.9ah.1 r/w serial clock selection flag bit 1 siock0 flg 0.9ah.0 r/w serial clock selection flag bit 0
chapter 19 assembler reserved words 256 ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... register file (control register) (2/2) symbol name attribute value read/write description iegmd1 flg 0.9fh.1 r/w int pin edge detection selection flag bit 1 iegmd0 flg 0.9fh.0 r/w int pin edge detection selection flag bit 0 p0bgio flg 0.a4h.0 r/w p0b group input/output selection flag (1= all p0bs are output ports.) ipsio flg 0.afh.2 r/w sio interrupt flag iptm flg 0.afh.1 r/w timer interrupt enable flag ip flg 0.afh.0 r/w int pin interrupt enable flag p0ebio1 flg 0.b2h.1 r/w p0e 1 input/output selection flag (1=output port) p0ebio0 flg 0.b2h.0 r/w p0e 0 input/output selection flag (1=output port) p0dbio3 flg 0.b3h.3 r/w p0d 3 input/output selection flag (1=output port) p0dbio2 flg 0.b3h.2 r/w p0d 2 input/output selection flag (1=output port) p0dbio1 flg 0.b3h.1 r/w p0d 1 input/output selection flag (1=output port) p0dbio0 flg 0.b3h.0 r/w p0d 0 input/output selection flag (1=output port) p0cbio3 flg 0.b4h.3 r/w p0c 3 input/output selection flag (1=output port) p0cbio2 flg 0.b4h.2 r/w p0c 2 input/output selection flag (1=output port) p0cbio1 flg 0.b4h.1 r/w p0c 1 input/output selection flag (1=output port) p0cbio0 flg 0.b4h.0 r/w p0c 0 input/output selection flag (1=output port) p0abio3 flg 0.b5h.3 r/w p0a 3 input/output selection flag (1=output port) p0abio2 flg 0.b5h.2 r/w p0a 2 input/output selection flag (1=output port) p0abio1 flg 0.b5h.1 r/w p0a 1 input/output selection flag (1=output port) p0abio0 flg 0.b5h.0 r/w p0a 0 input/output selection flag (1=output port) irqsio flg 0.bdh.0 r/w sio interrupt request flag irqtm flg 0.beh.0 r/w timer interrupt request flag irq flg 0.bfh.0 r/w int pin interrupt request flag peripheral hardware register symbol name attribute value read/write description siosfr dat 01h r/w peripheral address of the shift register tmc dat 02h r peripheral address of the timer count register tmm dat 03h w peripheral address of the timer modulo register ar dat 40h r/w peripheral address of the address register for get, put, push, call, br, movt, and inc instructions
chapter 19 assembler reserved words 257 others symbol name attribute value description dbf dat 0fh fix operand value of put, get, movt instructions ix dat 01h fix operand value of inc instruction
chapter 19 assembler reserved words 258 column address row address item symbol at reset read/ write symbol at reset read/ write symbol at reset read/ write symbol at reset read/ write 0 0 r/w 0 0 0 0 p d r e s e n 0 0 0 (8) 1 (9) 2 (a) 3 (b) 1 234 56 7 t m e n 1 r/w t m r e s 0 t m c k 1 0 t m c k 0 0 0 0 r/w 0 0 0 0 t m o s e l 0 0 0 r/w 0 s p 00 0 0 r/w 0 0 0 0 p 0 b g i o 0 0 0 r/w 0 00 p 0 e b i o 0 00 r/w 00 p 0 d b i o 0 0 p 0 e b i o 1 p 0 d b i o 2 p 0 d b i o 3 p 0 d b i o 1 0 r/w 00 p 0 c b i o 0 0 p 0 c b i o 2 p 0 c b i o 3 p 0 c b i o 1 0 r/w 00 p 0 a b i o 0 0 p 0 a b i o 2 p 0 a b i o 3 p 0 a b i o 1 figure 19-1. configuration of control register ( m pd17120, 17121) (1/2) remark ( ) means the address when using assembler (as17k). all flags of the control register are registered in device file as assembler reserved words. it is convenient for program design to use the reserved words.
chapter 19 assembler reserved words 259 8 9 abcde f s i o t s 0 r/w s i o h i z 0 s i o c k 1 0 s i o c k 0 0 0 0 r/w 0 00 i e g m d 0 0 0 0 r/w 0 s i o e n 00 0 0 r/w 0 0 0 0 i r q 0 i e g m d 1 00 0 0 r 0 i n t 0 note 00 0 0 r/w 00 i p 0 i p t m i p s i o r/w 0 0 0 0 i r q t m 1 0 0 r/w 0 0 0 0 i r q s i o 0 0 0 figure 19-1. configuration of control register ( m pd17120, 17121) (2/2) note the int flag differs depending on the int pin state at the time.
chapter 19 assembler reserved words 260 19.2.2 list of reserved symbols ( m pd17132, 17133, 17p132, 17p133) system register (sysreg) symbol name attribute value read/write description ar3 mem 0.74h r address register bits 15 to 12 ar2 mem 0.75h r/w address register bits 11 to 8 ar1 mem 0.76h r/w address register bits 7 to 4 ar0 mem 0.77h r/w address register bits 3 to 0 wr mem 0.78h r/w window register bank mem 0.79h r/w bank register ixh mem 0.7ah r/w index register high mph mem 0.7ah r/w data memory row address pointer high mpe flg 0.7ah.3 r/w memory pointer enable flag ixm mem 0.7bh r/w index register middle mpl mem 0.7bh r/w data memory row address pointer low ixl mem 0.7ch r/w index register low rph mem 0.7dh r/w general register pointer high rpl mem 0.7eh r/w general register pointer low psw mem 0.7fh r/w program status word bcd flg 0.7eh.0 r/w bcd flag cmp flg 0.7fh.3 r/w compare flag cy flg 0.7fh.2 r/w carry flag z flg 0.7fh.1 r/w zero flag ixe flg 0.7fh.0 r/w index enable flag
chapter 19 assembler reserved words 261 ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... data buffer (dbf) symbol name attribute value read/write description dbf3 mem 0.0ch r/w dbf bits 15 to 12 dbf2 mem 0.0dh r/w dbf bits 11 to 8 dbf1 mem 0.0eh r/w dbf bits 7 to 4 dbf0 mem 0.0fh r/w dbf bits 3 to 0 port register symbol name attribute value read/write description p0e1 flg 0.6fh.1 r/w port 0e bit 1 p0e0 flg 0.6fh.0 r/w port 0e bit 0 p0a3 flg 0.70h.3 r/w port 0a bit 3 p0a2 flg 0.70h.2 r/w port 0a bit 2 p0a1 flg 0.70h.1 r/w port 0a bit 1 p0a0 flg 0.70h.0 r/w port 0a bit 0 p0b3 flg 0.71h.3 r/w port 0b bit 3 p0b2 flg 0.71h.2 r/w port 0b bit 2 p0b1 flg 0.71h.1 r/w port 0b bit 1 p0b0 flg 0.71h.0 r/w port 0b bit 0 p0c3 flg 0.72h.3 r/w port 0c bit 3 p0c2 flg 0.72h.2 r/w port 0c bit 2 p0c1 flg 0.72h.1 r/w port 0c bit 1 p0c0 flg 0.72h.0 r/w port 0c bit 0 p0d3 flg 0.73h.3 r/w port 0d bit 3 p0d2 flg 0.73h.2 r/w port 0d bit 2 p0d1 flg 0.73h.1 r/w port 0d bit 1 p0d0 flg 0.73h.0 r/w port 0d bit 0
chapter 19 assembler reserved words 262 register file (control register) (1/2) symbol name attribute value read/write description sp mem 0.81h r/w stack pointer sioen flg 0.8ah.0 r sio enable flag int flg 0.8fh.0 r/w int pin status flag pdresen flg 0.90h.0 r/w power-down reset enable flag tmen flg 0.91h.3 r/w timer enable flag tmres flg 0.91h.2 r/w timer reset flag tmck1 flg 0.91h.1 r/w timer source clock selection flag bit 1 tmck0 flg 0.91h.0 r/w timer source clock selection flag bit 0 tmosel flg 0.92h.0 r/w timer output port/port selection flag siots flg 0.9ah.3 r/w sio start flag siohiz flg 0.9ah.2 r/w so pin status siock1 flg 0.9ah.1 r/w sio source clock selection flag bit 1 siock0 flg 0.9ah.0 r/w sio source clock selection flag bit 0 cmpch1 flg 0.9ch.1 r/w comparator input channel selection flag bit 1 cmpch0 flg 0.9ch.0 r/w comparator input channel selection flag bit 0 cmpvref3 flg 0.9dh.3 r/w comparator reference voltage selection flag bit 3 cmpvref2 flg 0.9dh.2 r/w comparator reference voltage selection flag bit 2 cmpvref1 flg 0.9dh.1 r/w comparator reference voltage selection flag bit 1 cmpvref0 flg 0.9dh.0 r/w comparator reference voltage selection flag bit 0 cmpstrt flg 0.9eh.1 r comparator start flag cmprslt flg 0.9eh.0 r/w comparator comparison result flag iegmd1 flg 0.9fh.1 r/w int pin edge detection selection flag bit 1 iegmd0 flg 0.9fh.0 r/w int pin edge detection selection flag bit 0 p0c3idi flg 0.a3h.3 r/w p0c 3 input port disable flag (p0c 3 /cin 3 selection) p0c2idi flg 0.a3h.2 r/w p0c 2 input port disable flag (p0c 2 /cin 2 selection) p0c1idi flg 0.a3h.1 r/w p0c 1 input port disable flag (p0c 1 /cin 1 selection) p0c0idi flg 0.a3h.0 r/w p0c 0 input port disable flag (p0c 0 /cin 0 selection) p0bgio flg 0.a4h.0 r/w p0b group input/output selection flag (1= all p0es are output ports.) ipsio flg 0.afh.2 r/w sio interrupt flag iptm flg 0.afh.1 r/w timer interrupt enable flag ip flg 0.afh.0 r/w int pin interrupt enable flag p0ebio1 flg 0.b2h.1 r/w p0e 1 input/output selection flag (1=output port) p0ebio0 flg 0.b2h.0 r/w p0e 0 input/output selection flag (1=output port) p0dbio3 flg 0.b3h.3 r/w p0d 3 input/output selection flag (1=output port) p0dbio2 flg 0.b3h.2 r/w p0d 2 input/output selection flag (1=output port) p0dbio1 flg 0.b3h.1 r/w p0d 1 input/output selection flag (1=output port) p0dbio0 flg 0.b3h.0 r/w p0d 0 input/output selection flag (1=output port) ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ...................................................
chapter 19 assembler reserved words 263 ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... ............................................................................................................................... ................................................... register file (control register) (2/2) symbol name attribute value read/write description p0cbio3 flg 0.b4h.3 r/w p0c 3 input/output selection flag (1=output port) p0cbio2 flg 0.b4h.2 r/w p0c 2 input/output selection flag (1=output port) p0cbio1 flg 0.b4h.1 r/w p0c 1 input/output selection flag (1=output port) p0cbio0 flg 0.b4h.0 r/w p0c 0 input/output selection flag (1=output port) p0abio3 flg 0.b5h.3 r/w p0a 3 input/output selection flag (1=output port) p0abio2 flg 0.b5h.2 r/w p0a 2 input/output selection flag (1=output port) p0abio1 flg 0.b5h.1 r/w p0a 1 input/output selection flag (1=output port) p0abio0 flg 0.b5h.0 r/w p0a 0 input/output selection flag (1=output port) irqsio flg 0.bdh.0 r/w sio interrupt request flag irqtm flg 0.beh.0 r/w timer interrupt request flag irq flg 0.bfh.0 r/w int pin interrupt request flag peripheral hardware register symbol name attribute value read/write description siosfr dat 01h r/w peripheral address of the shift register tmc dat 02h r peripheral address of the timer count register tmm dat 03h w peripheral address of the timer modulo register ar dat 40h r/w peripheral address of the address register for get, put, push, call, br, movt, and inc instructions others symbol name attribute value description dbf dat 0fh fix operand value of put, get, movt instructions ix dat 01h fix operand value of inc instruction
chapter 19 assembler reserved words 264 figure 19-2. configuration of control register ( m pd17132, 17133, 17p132, 17p133) (1/2) column address row address item symbol at reset read/ write symbol at reset read/ write symbol at reset read/ write symbol at reset read/ write 0 0 r/w 0 0 0 0 p d r e s e n 0 0 0 (8) 1 (9) 2 (a) 3 (b) 1 234 56 7 t m e n 0 r/w t m r e s 0 t m c k 1 0 t m c k 0 0 0 0 r/w 0 0 0 0 t m o s e l 0 0 0 r/w 1 s p 01 0 0 r/w 0 0 0 0 p 0 b g i o 0 0 0 r/w 0 00 p 0 e b i o 0 00 r/w 00 p 0 d b i o 0 0 p 0 e b i o 1 p 0 d b i o 2 p 0 d b i o 3 p 0 d b i o 1 0 r/w 00 p 0 c b i o 0 0 p 0 c b i o 2 p 0 c b i o 3 p 0 c b i o 1 0 r/w 00 p 0 a b i o 0 0 p 0 a b i o 2 p 0 a b i o 3 p 0 a b i o 1 0 r/w 00 p 0 c 0 i d i 0 p 0 c 2 i d i p 0 c 3 i d i p 0 c 1 i d i remark ( ) means the address when using assembler (as17k). all flags of the control register are registered in device file as assembler reserved words. it is convenient for program design to use the reserved words.
chapter 19 assembler reserved words 265 8 9 abcde f s i o t s 0 r/w s i o h i z 0 s i o c k 1 0 s i o c k 0 0 0 0 r/w 0 00 i e g m d 0 0 0 0 r/w 0 s i o e n 00 0 0 r/w 0 0 0 0 i r q 0 i e g m d 1 00 0 0 r 0 i n t 0 00 0 0 r/w 00 i p 0 i p t m i p s i o r/w 0 0 0 0 i r q t m 1 0 0 r/w 0 0 0 0 i r q s i o 0 0 0 0 0 0 0 00 c m p r s l t c m p s t r t 1 r r/w r/w 0 c m p v r e f 0 0 c m p v r e f 1 0 c m p v r e f 2 1 c m p v r e f 3 0 0 0 00 c m p c h 1 c m p c h 1 0 r/w figure 19-2. configuration of control register ( m pd17132, 17133, 17p132, 17p133) (2/2) note the int flag differs depending on the int pin state at the time.
266 [memo]
af-9703 note 3 af-9704 note 3 af-9705 note 3 af-9706 note 3 appendix a development tools the following support tools are available for developing programs for the m pd17120 subseries. hardware name outline in-circuit emulator ie-17k, ie-17k-et, and emu-17k are the in-circuit emulators common to all ie-17k 17k-series products. ie-17k-et note 1 ie-17k and ie-17k-et are used by connecting to the host machine pc-9800 emu-17k note 1 series or ibm pc/at tm through rs-232-c. emu-17k is used by installing in the expansion slot of the host machine pc-9800 series. by using it in combination with the system evaluation board (se board) dedicated to the relevant machine type, the emulator can perform opera- tions compatible with it. an even more advanced debugging environment can be realized by using simplehost, which is man-machine interface software. emu-17k is equipped with the function of checking the contents of the data memory in a real-time environment. se board the se-17120 is an se board for the m pd17120 subseries. the board is (se-17120) used for evaluation of single system units as well as for debugging by being combined with an in-circuit emulator. emulation probe the ep-17120cs, which is the emulation probe for the m pd17120 sub- (ep-17120cs) series, connects between an se board and a target system. prom programmer af-9703, af-9704, af-9705, and af-9706 are the prom programmers compatible with the m pd17p132 and 17p133. by connecting them to the program adapter af-9808m, the m pd17p132 and 17p133 are enabled for programming. program adapter the af-9808m, which is an adapter for programming the m pd17p132cs, (af-9808m note 3 ) 17p132gt, 17p132cs, and 17p33gt, is used in combination with the af- 9703, af9704, af-9705, or af-9706. notes 1. low-price version: external-power type 2. this is a product of i.c co., ltd. for further details, please contact i.c co. in tokyo (tel: 03-3447- 3793). 3. this is the product of the ando electric, ltd. for further details, please contact ando electric co., ltd. in tokyo (tel: 03-3733-1151). 267
appendix a development tools 268 17k-series as17k is an assembler assembler which can be used in (as17k) common for the 17k series. for program development of the m pd17120 series, as17k and device files (as17120, as17121, as17132, as17133) are used together. device as17120, as17121, files as17132, and as17133 as17120 are the device files for the as17121 m pd17120 subseries. as17132 these are used in combi- as17133 nation with the assembler (as17k) common to the 17k series. support this software is used for software machine interfacing on (simple- windows tm when doing host) program development by means of an in-circuit emulator and a personal computer. pc-9800 series ms-dos tm ibm pc/at pc dos tm pc-9800 series ms-dos ibm pc/at pc dos pc-9800 series ms-dos ibm pc/at pc dos 5-inch 2hd m s5a10as17k 3.5-inch 2hd m s5a13as17k 5-inch 2hc m s7b10as17k 3.5-inch 2hc m s7b13as17k 5-inch 2hd m s5a10as17120 note 3.5-inch 2hd m s5a13as17120 note 5-inch 2hc m s7b10as17120 note 3.5-inch 2hc m s7b13as17120 note 5-inch 2hd m s5a10ie17k 3.5-inch 2hd m s5a13ie17k 5-inch 2hc m s7b10ie17k 3.5-inch 2hc m s7b13ie17k software name outline host machine os supply medium part number windows note m s as17120 contains as17120, as17121, as17132, and as17133. remark compatible os versions include the following: os version ms-dos ver. 3.30 to ver. 5.00a note pc dos ver. 3.1 to ver. 5.0 note windows ver. 3.0 to ver. 3.1 note ms-dos vers. 5.00/5.00a and pc dos ver. 5.0 are equipped with the task swap function. however, this software is not.
appendix b ordering mask rom after developing the program, place an order for the mask rom version, according to the following procedure: (1) make reservation when ordering mask rom. advice nec of the schedule for placing an order for the mask rom. if nec is not informed in advance, on- time delivery may not be possible. (2) create ordering medium. use uv-eprom to place an order for the mask rom. add/prom as an assemble option of the assembler (as17k), and create a mask rom ordering hex file (with extender for .pro). next, write the mask rom ordering hex file into the uv-eprom. create three uv- eproms with the same contents. (3) prepare necessary documents. fill out the following forms to place an order for the mask rom: ? mask rom ordering sheet ? mask rom ordering check sheet (4) ordering submit the media created in (2) and documents prepared in (3) to nec by the specified date. 269
[memo] 270
appendix c cautions to take in system clock oscillation circuit configurations the system clock oscillation circuit operates with a ceramic resonator connected to the x1 and x2 pins or with an oscillation resistor connected to the osc 1 and osc 0 pins. figure c-1 shows the externally installed system clock oscillation circuit. figure c-1. externally installed system clock oscillation circuit m pd17121 m pd17133 m pd17p133 x out x in gnd ceramic resonator m pd17120 m pd17132 m pd17p132 osc 1 osc 0 oscillation resistor caution regarding the system clock oscillation circuit, make sure that its ground wire's resistance component and impedance component are minimized. also, to avoid the effect of wiring capacity, etc., please wire the part encircled in the dotted line in figure c-1 in the manner described below: ? make the wiring as short as possible. ? do not allow it to intersect other signal conductors. do not let it be near lines in which a large fluctuating current flows. ? make sure that the grounding point of the oscillation circuit's capacitor is constantly at the same electric potential as v ss . do not let it be near a gnd wire in which a large current flows. ? do not extract signals from the oscillation circuit. figure c-2 shows unsatisfactory oscillation circuit examples. 271
appendix c cautions to take in system clock oscillation circuit 272 figure c-2. unsatisfactory oscillation circuit examples (a) connecting circuit whose wiring is too long (b) signal conductors are intersecting (c) functuating large current located (d) current flowing in the gnd line of the too close to the signal conductor oscillation circuit (points a and b's potentials change as to point c.) (e) signals are being extracted x in gnd x out port x in gnd x out port ab c large-volume current x in gnd x out large current x in gnd x out x in gnd x out too long
appendix d instruction list [a] movt dbf, @ar229 add m, #n4193 add r, m189 [n] addc m, #n4198 nop249 addc r, m195 and m, #n4214 [o] and r, m213 or m, #n4212 or r, m211 [b] br addr239 [p] br @ar240 peek wr, rf234 poke rf, wr235 [c] pop ar233 call addr217 push ar230 call @ar:242 put p, dbf238 [d] [r] di248 ret245 reti246 [e] retsk245 ei247 rorc r221 [g] [s] get dbf, p236 ske m, #n4218 skf m, #n217 [h] skge m, #n4220 halt h249 sklt m, #n4220 skne m, #n4219 [i] skt m, #n216 inc ar199 st m, r224 inc ix201 stop s249 sub m, #n4205 [l] sub r, m202 ld r, m222 subc m, #n4209 subc r, m207 [m] mov m, #n4229 [x] mov m, @r227 xor m, #n4216 mov @r, m225 xor r, m214 273
[memo] 274


▲Up To Search▲   

 
Price & Availability of UPD17132GT-XXX

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X